When I built using the build.gradle file as shown below, a jar file was generated, but the class file did not exist in it.
build.gradle
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'
}
The cause of this event was that the java file existed under / src
.
I am using a Java plugin this time, but if this plugin is left as default, it will build java files under / src / main / java
.
So, when I moved the java file under / src / main / java
and built it, the class file was successfully generated in the jar file.
This time, there was a background of changing the project that was originally built with Ant to build with Gradle, and I was not very conscious of the directory structure of the source, so there was such a condition in the Java plugin. Did not know.
By the way, you can also set the build target directory by using sourceSets
as shown in here. I will.
This time, I took the policy of moving the source under / src / main / java
in consideration of the unity with other projects, but I think this policy is also smart.
If the class file does not exist in the jar file generated using Gradle, please check the directory structure and what the directory to build Gradle is.
If you are using a Java plugin, the java files under / src / main / java
are built by default, so match the directory structure to this or set the directory to be referenced when building. Be sure to set it explicitly.
Recommended Posts