Gradle: how to configure buildSrc or skip tests from main project?

build.gradle, gradle, groovy, junit

Solution

`buildSrc` is a separate build (not project), and I'm not aware of a way to influence its execution when triggering the main build. (Note that building `buildSrc` is a prerequisite for evaluating the main build's build scripts.) Some solutions I can think of:

- Unconditionally disable `buildSrc` tests for as long as required (e.g. by setting `test.disabled = true` in `buildSrc/build.gradle`)

- Factor out `buildSrc` into a separate build

- Change tests so that they are insensitive to template changes

- Move tests that are sensitive to template changes into a separate `Test` task that's only triggered manually

PS: The easiest way to skip a build's tests from the command line is `-x test`. The existence of a project property `foo` can be detected with `project.hasProperty("foo")`.

Problem

I have some fairly long tests in my buildSrc build which I sometimes want to skip during development, to see the effect that template changes have. It's a report generator and sometimes I just want to tweak the templates without having to update all the tests; then later I will update them when I'm happy with the output. I was able to implement skipping tests within the buildSrc build.gradle with the following configuration: ``` test { // skip all tests if gradle run with -Pnotests try { if (project.ext.notests != null) println "skipping tests" exclude '**' } catch (MissingPropertyException e) {} } ``` (and if you have a better way to detect an optional parameter I'd love to see it) However, this doesn't work from the main gradle project. I have tried everything I can think of to try to pass the parameter through configuration, short of setting an environment variable, but I doubt that would work either. In general I find I can't configure buildSrc whatsoever from the main project. I can't find any way to get at variables, eg project.ext.foo or ext.foo, nor a way to configure the buildSrc 'project' as there is no section in main build.gradle. It's like it exists on an island of its own. I've tried: - project.ext.notests = true - test {...} in main - allprojects { test {...} } - subprojects { test {...} } - dependencies { test {...} } - buildscript { test {...} } Is there a way around this, or do I have to refactor my whole project to move the reporting code elsewhere and maybe then I can configure it and skip tests? Thanks in advance.

Original source