Click the link and explore which tasks where executed, which dependencies where downloaded and many more details! This can be done like so: dependencies { compile fileTree(dir: 'libs', include: '*.jar') } Where libs would be the directory containing the jars and *.jar would be the filter of which files to include. Congratulations, you have just completed the first step of creating a Java library! The settings.gradle(.kts) file has two active line: rootProject.name assigns a name to the build, which overrides the default behavior of naming the build after the directory it’s in. Add a Local JAR File Dependency. Version is used for the Gradle property project.version value in the build.gradle file. We can see the extension doesn't seem to be treating this as a multi-project build and is not using the Gradle wrapper for the subprojects. For this example, enter my_gradle_plugin. In this journal entry, we will be journeying on “How to Build Java Project using Gradle”. For e.g. It is also used for the Gradle property rootProject.name value in the project’s settings.gradle file. For the other questions, press enter to use the default values. The name is directly derived from the subproject name that represents the library. The java-library plugin has built-in support for Java’s API documentation tool via the javadoc task. It's also possible to add a directory of jars to compile. From inside the new project directory, run the init task using the following command in a terminal: gradle init. For this example, enter 1.0. A text editor or IDE - for example IntelliJ IDEA, A Java Development Kit (JDK), version 8 or higher - for example AdoptOpenJDK. Our build contains one subproject called lib that represents the Java library we are building. The resulting file is found in lib/build/libs, with a name using the conventional classifier -javadoc. A jar task that packages the main compiled classes and resources from src/main/resources into a single JAR named -.jar. This part builds on Part 2, where we looked at using the Java plugin in Gradle to compile/build our Java project. How to add JAR files to your Gradle project. You can now customize this to your own project needs. Build. Add .aar file to Android project using gradle. ArtifactId is the default name of the project JAR file (without version). However, this tutorial didn't really explain how any of this was supposed to work, and it seemed to assume that you were following some specific system for the layout of your project. To understand more of how gradle works, I went to the gradle site where they have tutorials for making a simple gradle setup for use when writing a java application (this is the one I found). You can unsubscribe at any time. More information about the features the java-library plugin adds to any JVM library project, such as API and implementation separation, can be found in the Java Library Plugin documentation. You’ll use the gradle build task frequently. When you execute the Build command, IntelliJ IDEA compiles all the classes inside your build … Run gradle tasks again, and you see new tasks added to the list, including tasks for building the project, creating JavaDoc, and running tests. NB: You will have to select a single approach for your module because if the same library will be attached to the project twice it will give compilation errors. The code generated by the Build Init plugin already placed a comment on the demo/Library.java file. Using the Jar Task From the Java Plugin. You can use the regular gradle command, but when a project includes a wrapper script, it is considered good form to use it instead. The best way to learn more about what your build is doing behind the scenes, is to publish a build scan. I created a very simple multi-project build (vscode-java-bug-gradle.zip). To build the project, run the build task. Dependencies. It is configured in the lib/build.gradle(.kts) file: The file src/main/java/demo/Library.java is shown here: The generated test, src/test/java/demo/Library.java is shown next: The generated test class has a single JUnit 4 test.