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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With