Gradle build without tests

后端 未结 13 1515
后悔当初
后悔当初 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:28

    You can exclude tasks

     gradle build --exclude-task test 
    

    https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_executing_tasks

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

    In The Java Plugin:

    $ gradle tasks
    
    Build tasks
    -----------
    assemble - Assembles the outputs of this project.
    build - Assembles and tests this project.
    testClasses - Assembles test classes.
    
    Verification tasks
    ------------------
    test - Runs the unit tests.
    

    Gradle build without test you have two options:

    $ gradle assemble
    $ gradle build -x test
    

    but if you want compile test:

    $ gradle assemble testClasses
    $ gradle testClasses
    
    0 讨论(0)
  • 2020-12-12 09:35

    Every action in gradle is a task, and so is test. And to exclude a task from gradle run, you can use the option --exclude-task or it's shorthand -x followed by the task name which needs to be excluded. Example:

    gradle build -x test
    

    The -x option should be repeated for all the tasks that needs to be excluded.

    If you have different tasks for different type of tests in your build.gradle file, then you need to skip all those tasks that executes test. Say you have a task test which executes unit-tests and a task testFunctional which executes functional-tests. In this case, you can exclude all tests like below:

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

    Using -x test skip test execution but this also exclude test code compilation.

    gradle build -x test 
    

    In our case, we have a CI/CD process where one goal is compilation and next goal is testing (Build -> Test).

    So, for our first Build goal we wanted to ensure that the whole project compiles well. For this we have used:

    ./gradlew build testClasses -x test
    

    On the next goal we simply execute tests.

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

    You can add the following lines to build.gradle, **/* excludes all the tests.

    test {
        exclude '**/*'
    }
    
    0 讨论(0)
  • 2020-12-12 09:40

    Please try this:

    gradlew -DskipTests=true build

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