首页 文章

没有测试的Gradle构建

提问于
浏览
457

我想执行 gradle build 而不执行单元测试 . 我试过了:

$ gradle -Dskip.tests build

这似乎没有做任何事情 . 我还可以使用其他命令吗?

7 回答

  • 908

    尝试:

    gradle assemble
    

    要列出项目的所有可用任务,请尝试:

    gradle tasks
    

    更新:

    这看起来似乎不是最正确的答案,但请仔细阅读 gradle tasks 输出或文档 .

    Build tasks
    -----------
    assemble - Assembles the outputs of this project.
    build - Assembles and tests this project.
    
  • 28

    Reference

    要从gradle中排除任何任务,请使用 -x 命令行选项 . 请参阅以下示例

    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'
    }
    

    产量: gradle -q dist -x runningTest

    task compile
    compile test
    running distribution job
    

    希望这会给你基本的

  • 4
    gradle build -x test --parallel
    

    如果您的计算机有多个核心 . 但是,不建议使用平行清洁 .

  • 1

    您可以尝试将以下行添加到 build.gradle**/* 排除所有测试 .

    test {
        exclude '**/*'
    }
    
  • 0

    在项目中禁用测试任务的不同方法是:

    tasks.withType(Test) {enabled = false}
    

    如果要在项目(或项目组)之一中禁用测试,有时需要此行为 .

    这种方式适用于所有类型的测试任务,而不仅仅是java 'tests' . 而且,这种方式是安全的 . 这里's what I mean let'说:你有一组不同语言的项目:如果我们尝试在主_144599中添加这种记录:

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

    如果我们没有任何名为 tests 的任务,我们将在项目中失败

  • 75

    您应该使用排除任何任务的 -x 命令行参数 .

    尝试:

    gradle build -x test
    

    Update:

    彼得评论中的链接发生了变化 . 这是Gradle user's guidediagram

  • 2

    接受的答案是正确的答案 .

    OTOH,我以前解决这个问题的方法是将以下内容添加到所有项目中:

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

    使用 -Dskip.tests=true 运行构建,将跳过所有测试任务 .

相关问题