Home > Software design >  Create a Jar Library and import it in another gradle project using intelliJ
Create a Jar Library and import it in another gradle project using intelliJ

Time:07-10

I created a jar Library(i.e. without main class) of gradle project using the below steps Files -> Project Structure -> Artifacts -> -> jar -> From modules with dependencies -> all modules -> extract to a target jar -> Ok -> Build -> Build Artifacts.

Is this the correct way to build a jar without the main class? because I'm getting errors when I try to import it into another Gradle project. Suppose jar file name is test.jar

I added jar into src/libs/test.jar

In build.gradle dependencies I added implementation fileTree(dir: 'libs', include: ['*.jar'])

Right click on test.jar -> add to library -> module test

Files -> Project Structure -> modules -> dependencies -> -> test.jar -> Ok

Still getting class not found error and can't find symbol error

CodePudding user response:

If you want to create a library to use in other Gradle projects, you should create also a Gradle project for the library, so you don't have to specify some arbitrary file path references but can use proper Maven GAV coordinates (GAV = group/artifact/version)

To create a Gradle lib project, you can follow the steps in the official Gradle documentation and I really would recommend that over some built in stuff in IDEA (that I value very much btw), because you then will learn how to work independent from your IDE - which can help, when you have to use something different in another project.

  • Related