0

I have written a tool OwnerFinder that does some annotation processing on some jars of an application. I need to expose this tool on TeamCity so have written a gradle script which performs following tasks

  1. Extract the application zip file
  2. Copy the application jars to a location build/appJars
  3. compile tool OwnerFinder (keep the appJars in the classpath)
  4. create jar of OwnerFinder
  5. Run OwnerFinder(keep the appJars in the classpath)

(I need to keep the app jars in the class path because the annotation for which processing needs to be done is in those jars)

But somehow the order of the task is not guaranteed even after using dependsOn and mustRunAfter. The script fails either at

  1. compilation task (where its not able to find the annotation in the dependencies) or
  2. run task where its not able to find the class OwnerFinder

but after 2nd or 3rd try it runs sucessfully. This makes me think that the gradle tasks are not executing as per order.

Following is my gradle script:-

apply from: 'http://some-gradle-util-script'
apply plugin: 'java'


def confs = ["someApplicationConf"]
confs.each { configurations.create it }
configurations { sources }

configureDownload('ivy', 'ivy-integrated')

dependencies {
    def someApplicationVersion = '1.12.0.+'
    someApplicationConf "com.soft:someApplication-sync:${someApplicationVersion}@zip"
    compile 'com.google.guava:guava:16.0.1',
            'com.google.code.gson:gson:2.2.2'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

task unzip(type: Copy, dependsOn: clean) {
        from zipTree(configurations.someApplicationConf.singleFile)
        into "$buildDir/unzipped"
}

task copyJar(type: Copy, dependsOn: unzip) {
    from "$buildDir/unzipped/modules"
    into "$buildDir/op"
}

copyJar.mustRunAfter unzip

task compileOwnerFinder(type: JavaCompile, dependsOn: copyJar) {
    FileCollection f = files(fileTree(dir: 'build/op', include: '*.jar').files, configurations.compile.files)
    source = fileTree(dir: 'src', include: '**/*.java')
    classpath = f
    destinationDir = new File("$buildDir/classes/main")
}

compileOwnerFinder.mustRunAfter copyJar

task jarOwnerFinder(type: Jar, dependsOn: compileOwnerFinder) {
    from files(sourceSets.main.output.classesDir)
}

task runOwnerFinder(type: Exec, dependsOn: jarR) {
    def classpath = fileTree(dir: 'build/op', include: '*.jar').files + configurations.compile.files +
            fileTree(dir: 'build/libs', include: '*.jar').files
    commandLine "java", "-classpath", classpath.join(File.pathSeparator), "OwnerFinder"
}
runOwnerFinder.mustRunAfter jarOwnerFinder
3
  • 1
    what does the output of gradle -m compileOwnerFinder look like? Dec 22, 2015 at 8:08
  • E:\OwnerFinder>gradle -m compileOwnerFinder Download <some path torepo>/1.12.0.594/ivy-1.12.0.594.xml Download <some path torepo>/1.12.0.594/zip/someApplication-sync-1.12.0.594.zip :clean SKIPPED :unzip SKIPPED :copyJar SKIPPED :compileOwnerFinder SKIPPED BUILD SUCCESSFUL dont know why it skipped these tasks
    – Parikshit
    Dec 22, 2015 at 9:10
  • 1
    '-m' always skips tasks and just illustrates the invocation order of the tasks. I just wondered if the task dependencies show up correctly Dec 22, 2015 at 16:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.