简体   繁体   中英

Why there is no .class file in my jar file created by gradle?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM