Reputation: 462
My project depends on a bunch of jar files that are not in a Maven repository. I can declare them as file dependencies, but I'd rather use Gradle's dependency manager, so I need to install them to local Maven repository.
I'm thinking about writing a task, say, "installFiles", and making "compileJava" depend on it, so it will be run first, and these dependencies will appear in local Maven repository before compilation. Then I'm going to declare them as normal external module dependencies, so that Gradle's dependency manager can handle them.
My question is, how do I install a bunch of jars to a local Maven repository? All documentation I've found just talks about installing the result of the current project, not some arbitrary jars.
Upvotes: 1
Views: 3851
Reputation: 38619
Just follow the Gradle Documentation
here a quote for convenience:
apply plugin: "maven-publish"
publishing {
publications {
maven(MavenPublication) {
artifact 'my-file-name.jar' // Publish a file created outside of the build
}
}
}
Upvotes: 4
Reputation: 23647
Where are you getting these arbitrary jars? Where can you get their POM information like moduleId, groupID, version etc?
You may be able to create a gradle task to construct the POM and then publish to a maven repo, but I think a simpler solution is to just use maven for the initial publishing. You can just run this maven command
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \
-Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar \
-DlocalRepositoryPath=path-to-specific-local-repo
If you skip the last parameter, the artifact will be published to default local repo declared in maven settings.xml
Couple of things you should think about while doing this:
Your build is only valid on your local machine. Since the jars you're pushing to your local repo are unique to your build setup, your project is no longer portable.
If your jars have dependencies of their own, the answer above does not generate that information in the POMs, you either have to add it in yourself or manage transitive dependencies manually in downstream projects.
Upvotes: 2