Run gradle build without running tests

By devin, 4 February, 2022

Gradle doesn't really expose an option for you to run your build without running tests. We were able to make this work by looking for an environment variable:

checkstyleMain.onlyIf { !System.getenv('SKIP_TESTS') }
checkstyleTest.onlyIf { !System.getenv('SKIP_TESTS') }
compileTestJava.onlyIf { !System.getenv('SKIP_TESTS') }
jacocoTestCoverageVerification.onlyIf { !System.getenv('SKIP_TESTS') }
test.onlyIf { !System.getenv('SKIP_TESTS') }

This means I can run, for example, SKIP_TESTS=true gradle build and it won't complain about checkstyle errors.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.