Reputation: 59
I create a jar file by Gradle(Ver 6.1.1) but there is no .class file in my jar file.
Created jar file contains only META-INF directory.
My build.gradle under root directory is following.
apply plugin: 'java'
group = 'com.test.foo'
version = '1.0.0'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
compileJava {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
dependencies {
implementation('org.slf4j:slf4j-api:1.7.21')
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
}
Then, I entered a following command.
$ gradle build
Of course there are many .java files under /src, but created jar file does not contains .class files.
I confirmed this question, but this is not useful for me because my using command is supplied by the plugin.
Why this phenomenon is happen? What should I fix?
■additional info
/build/classes directory does not also created.
Upvotes: 2
Views: 2520
Reputation: 6770
You wrote
Of course there are many .java files under /src, but created jar file does not contains .class files.
Gradle, by convention, compiles Java source files from folder src/main/java
. Make sure to either put your files in that folder (preferred) or configure Gradle to look into src
only.
Further reading: Organizing Gradle Projects
Upvotes: 1