How to create a library jar project

I’ve tried what I found on the Web, the only thing to work is ‘gradle init --type java-library’ and then it’s not obvious how to get rid of template stuff.

I have source files, I need to create a project which would assemble a jar file out of compiled classes. How can I create build.gradle - and do I need anything else?

Aha, looks like gradle doesn’t tolerate external manipulations with file system. So the solution so far is - have an absolutely empty project directory, run ‘gradle init --type java-library’ in it (gradle should already be installed and in the $PATH), then carefully replace test and code subdirectories with your own. Then you can remove “dependencies” and “repositories” sections in build.gradle unless you need them.

Good luck.


Here is a simple/minimal sample for a configuring a Java library:


  • add a build.gradle file with this content: plugins { id "java-library" }

Done. :slight_smile:

I’ve tried, but it seems the structure of project subdirectories is important. When I had a different layout of source, test and resourse files, this short build.gradle file didn’t seem to work.