问题
I'm trying to add a task (gen
or gen2
) to my build.gradle
that does exactly the same as the Jar
-task:
version = "0.0.1"
apply plugin: 'java'
task('gen', type: Jar) {
}
task gen2(type: Jar)
Running
gradle jar
generates a JAR-file that contains .class
-files, while running
gradle gen
or
gradle gen2
generate a JAR-file that does NOT contain any .class
-files.
Whats wrong with my class definition?
回答1:
To build a jar with all the classes from main, as a default jar
task would, do this:
task gen2(type: Jar){
baseName = 'gen2Jar'
from sourceSets.main.output
}
You can also do from(sourceSets.main.output){ include "package" }
to customize what packages are included.
Alternatively, to copy settings from the default jar
task:
task gen(type: Jar){
baseName = 'genJar'
with jar
}
Infact you can have both of these in the same build.gradle. Running gradle jar
builds default jar. gradle gen
builds genJar.jar and gradle gen2
builds gen2Jar.jar, all of which contain all the classes from java.main
来源:https://stackoverflow.com/questions/35919372/why-does-my-jar-file-not-not-contain-any-class-files