Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a jar and adding to another project as a library

I have java project build and executed successfully in IntelliJ using a gradle build tool. I want to create a jar file of this project and add it to the another project so that it can use this as a library. How can I create a jar and add it to another project?

like image 269
Tutu Avatar asked Oct 23 '25 00:10

Tutu


1 Answers

Maven Publish Plugin

The Maven Publish Plugin gives you a task called publishToMavenLocal. If you run that task like so in the project that is the one you wish to publish:

./gradlew publishToMavenLocal

this will publish a jar that you can pull into another project, assuming you have your group, module and version setup properly.

The group property you can set in your build.gradle, version in the gradle.properties and the module will be the name of the module that is being built unless specified otherwise.

You can check in your ~/.m2 directory to see that they were published with the correct group, module, and version.

Then in your consuming module, you can specify mavenLocal() in your repositories dsl block, and declare your published jar that you want to consume just like any other dependency.

like image 171
Rob Schwartz Avatar answered Oct 24 '25 13:10

Rob Schwartz