rupweb
rupweb

Reputation: 3328

gradle jar cant find java source

I am going through the gradle jar build example at https://guides.gradle.org/building-jvm-libraries/

The java source is not in a default src/main/java directory, it's in org\example\mylib directory. How can I customise gradle to run gradle jar from this directory and compile the java source files to a jar?

The whole directory structure is \mylib\src\main\java\org\example\mylib

When I am in that directory, and run gradle jar there is a success message but then when I check with jar -tf build/libs/mylib-0.1.0.jar all I see is the manifest files. There are no java classes.

If I try and run gradle jar in the \mylib directory alone, then it fails with error message Task 'jar' not found in root project

The build.gradle file is:

apply plugin: 'java' version = '0.1.0'

Upvotes: 1

Views: 1680

Answers (1)

Milan Markovic
Milan Markovic

Reputation: 1360

Try adding this to the gradle.build:

sourceSets {
    main {
        java {
            srcDirs = ['src\main\java\org\example\mylib']
        }
    }
}

Upvotes: 1

Related Questions