Hi All,
Im using Gradle 4.0 on Linux OS(Centos7), when i use my gradle script(build.gradle) to build jar file first time on Centos 7, it doesnt work only generate an empty jar file which doesnt have class file in jar, but when i repeat send same command to build jar file it works and the jar file doesnt empty again, how can i fix this issues?
my build jar file task was ‘release’ and the build.gradle are as fellows:
apply plugin: 'java’
apply plugin: ‘jacoco’
sourceCompatibility = 1.7
targetCompatibility = 1.7
compileJava.options.encoding = 'UTF-8’
version = ‘1.0’
sourceSets {
main {
resources {
srcDir ‘src/main/java’
}
}
}
repositories {
mavenCentral()
}
jacoco {
toolVersion = “0.7.6.201602180812"
reportsDir = file(”$buildDir/customJacocoReportDir")
}
dependencies {
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.+‘
compile fileTree(dir: ‘lib’, include: [’*.jar’])
}
task copyJars(type: Copy) {
from 'lib/'
into 'target/lib/'
it.setOnlyIf { true }
it.outputs.upToDateWhen { false }
}
task copyConfigureFiles(type: Copy){
from 'config’
into 'target/config/'
it.setOnlyIf { true }
it.outputs.upToDateWhen { false }
}
File classFolder =file(‘build/classes/java/main/’)
task taskJar(type:Jar, dependsOn: [copyJars,copyConfigureFiles,compileJava,compileTestJava]) {
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
baseName 'meu_addition'
if(classFolder.exists()){
from classFolder
include "/xxx/xxx/xxx/xxx/xxx/*.class"
}else{
from 'build/classes/main/'
include "/xxx/xxx/xxx/xxx/xxx/*.class"
}
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'xxx.xxx.xxx.xxx.xxx.Addition'
attributes 'Class-Path': 'config/ ' + configurations.compile.collect {'lib/' + it.getName()}.join(' ')
}
it.setOnlyIf { true }
it.outputs.upToDateWhen { false }
}
task release(type: Copy,dependsOn: taskJar) {
from(‘build/libs’) {
include ‘*.jar’
}
into (‘target’)
it.setOnlyIf { true }
it.outputs.upToDateWhen { false }
}