Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Build Library Jar with Gradle

Tags:

java

gradle

I followed this gradle tutorial:

https://guides.gradle.org/building-java-libraries/

with gradle 4.9 and for some reason in projects that reference the build jar can't see the Library class that should be created and be accessible once the project is built. I've changed nothing about the build settings and what not. Only run gradlew build from the command line to build the project.

I've tried finding the package path in my project, I've tried using eclipse to auto discover the import, it never finds it. (Note that the default method that the java-library type creates I've changed to static for my tests)

Am I missing something, I'm very new to Gradle and I'm trying to expose myself to it. But I'm familiar with just exporting a straight jar from the export window in Eclipse. So I can't quite determine what I'm doing wrong. Project Structure:

Gradle project

build.gradle file:

enter image description here

like image 654
brad95411 Avatar asked Oct 27 '25 08:10

brad95411


1 Answers

As per the gradle tutorial which you mentioned above, you first run the gradle init command which initializes the project by creating the project hierarchy for you as per the type. Your type is java-library.

Now run the gradle buildcommand. Build is also a implicit task which when executed creates the artifact(jar) for you under building-java-libraries\build\libs directory.

Please note that I was not able to see the build directory in eclipse but I could see the same in my eclipse workspace.

like image 191
Yug Singh Avatar answered Oct 28 '25 21:10

Yug Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!