Gradle build without tests

后端 未结 13 1513
后悔当初
后悔当初 2020-12-12 08:41

I want to execute gradle build without executing the unit tests. I tried:

$ gradle -Dskip.tests build

That doesn\'t seem to

相关标签:
13条回答
  • 2020-12-12 09:22
    gradle build -x test --parallel
    

    If your machine has multiple cores. However, it is not recommended to use parallel clean.

    0 讨论(0)
  • 2020-12-12 09:23

    You will have to add -x test

    e.g. ./gradlew build -x test

    or

    gradle build -x test
    
    0 讨论(0)
  • 2020-12-12 09:24

    The accepted answer is the correct one.

    OTOH, the way I previously solved this was to add the following to all projects:

    test.onlyIf { ! Boolean.getBoolean('skip.tests') }
    

    Run the build with -Dskip.tests=true and all test tasks will be skipped.

    0 讨论(0)
  • 2020-12-12 09:24

    Reference

    To exclude any task from gradle use -x command-line option. See the below example

    task compile << {
        println 'task compile'
    }
    
    task compileTest(dependsOn: compile) << {
        println 'compile test'
    }
    
    task runningTest(dependsOn: compileTest) << {
        println 'running test'
    }
    task dist(dependsOn:[runningTest, compileTest, compile]) << {
        println 'running distribution job'
    }
    

    Output of: gradle -q dist -x runningTest

    task compile
    compile test
    running distribution job
    

    Hope this would give you the basic

    0 讨论(0)
  • 2020-12-12 09:24

    the different way to disable test tasks in the project is:

    tasks.withType(Test) {enabled = false}
    

    this behavior needed sometimes if you want to disable tests in one of a project(or the group of projects).

    This way working for the all kind of test task, not just a java 'tests'. Also, this way is safe. Here's what I mean let's say: you have a set of projects in different languages: if we try to add this kind of record in main build.gradle:

     subprojects{
     .......
     tests.enabled=false
     .......
    }
    

    we will fail in a project when if we have no task called tests

    0 讨论(0)
  • 2020-12-12 09:27

    You should use the -x command line argument which excludes any task.

    Try:

    gradle build -x test 
    

    Update:

    The link in Peter's comment changed. Here is the diagram from the Gradle user's guide

    0 讨论(0)
提交回复
热议问题