Gradle - Create a jar only if you pass the tests

I am new to Gradle. For this, I would like to manipulate the following contents of build.gradle. Instead of running the tests separately and then building the bank using separate commands, I would like to do it as in one team, except that the bank is not created if one of the tests does not work (it will not even try to build the bank) .

apply plugin: 'java'
apply plugin: 'eclipse'

version = '1.0'
sourceCompatibility = 1.6
targetCompatibility = 1.6

// Create a single Jar with all dependencies
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',  
            'Implementation-Version': version,
            'Main-Class': 'com.axa.openam'
    }

    baseName = project.name

    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it) 
        }
    }
}

// Get dependencies from Maven central repository
repositories {
    mavenCentral()
}

test {
    testLogging {
        showStandardStreams = true
    }
}

// Project dependencies
dependencies {
    compile 'com.google.code.gson:gson:2.5'
    testCompile 'junit:junit:4.12'
}

Thank!

+4
source share
1 answer

The easiest solution is to put all the tasks you want to complete gradlein order. Therefore, you can use the following:

gradle clean test jar

Breakthrough tasks

  • clean: this is mainly used to safely remove the last obsolete jar (this is optional);
  • test: ;
  • jar: jar.

: - , gradle .

, , - , jar .


: 'test' jar '

: build.gralde :

[...]
jar {
    dependsOn 'test'
    [...]
}
[...]

, gradle jar, test .


'dependOn'

(.. gradle clean test jar) , build.gradle. , , dependsOn :

[...]
jar {
    dependsOn 'clean'
    dependsOn 'test'
    tasks.findByName('test').mustRunAfter 'clean'
    [...]
}
[...]

:

gradle jar

clean test ( ) jar.

+6

Source: https://habr.com/ru/post/1649432/


All Articles