Building the buildSrc project explicitly


(Wujek Srujek) #1

How can I build / test the buildSrc project? When I am in the top level directory (which contains buildSrc) and invoke my goals, Gradle automatically builds the buildSrc project. Ok. But when I am in the buildSrc directory, and invoke, say, ‘clean’, or ‘build’, or ‘check’, it fails with a message:

Task ‘clean’ not found in root project ‘buildSrc’.

and similar. How am I supposed to configure this project so that I can just build it like others?

I also read that you plan to ditch the buildSrc project in favour of letting the user explicitly configure such builds themselves, and telling gralde how to build them (there was a lengthy proposal from Adam Murdoch (sorry if I am mistaken!) somewhere) - how is that going?

wujek


(Peter Niederwieser) #2

To build ‘buildSrc’ explicitly, add a ‘build.gradle’. Work on more generic multi-build capabilities hasn’t started.


(Wujek Srujek) #3

What should be in the build gradle? Should it be empty (doesn’t seem to work)? I thought by default apply plugin: ‘groovy’ is used there, which would add the clean task and others, but this doesn’t work. Do I have to explicitly apply plugins, configure localGroovy() and gradleApi() deps?

wujek


(Peter Niederwieser) #4

Yes you do. An explicit ‘build.gradle’ in ‘buildSrc’ overrides the implicit one.


(Wujek Srujek) #5

So this is at odds with the current documentation (right above example 52.3): If you need more flexibility, you can provide your own build.gradle. Gradle applies the default build script regardless of whether there is one specified. This means you only need to declare the extra things you need. Below is an example. Notice that this example does not need to declare a dependency on the Gradle API, as this is done by the default build script: repositories {

mavenCentral() }

dependencies {

testCompile group: ‘junit’, name: ‘junit’, version: ‘4.8.2’ }

I understood from this text that the build.gradle files are ‘merged’, and the default is always applied.


(Luke Daley) #6

If you’re building this as a standalone project, i.e. not as the implicit ‘buildSrc’ of another project, then none of the defaults apply and you have to do everything explicitly.

This is one of the issues with this approach and why we are going to be working on a better approach.