Gradle script file with name other than build.gradle

(jacob.costa) #1


I have a Gradle project with diferent 2 main build scripts. The idea is that one of it is to be used from the development team and the other from our Continuous Integration server (Hudson). Although they are similar in lots of aspects there are smal differences.

To do this I’ve decided that there’s a main gradle script (common.gradle) which as almost every configuration. This script is to be called from 2 other scripts build.gradle and hudson.gradle. Both script files start with apply from: ‘common.gradle’.

The Gradle project structure consists of several subprojects.

The problem I’m facing is that whenever I execute the script that isn’t called build.gradle the build fails. If I rename the script build.gradle, which works, to another name, it stops working.

Is there anything that should be done whenever the script is not called build.gradle? The error I’m facing is the following:

00:54:38.942 [ERROR] [org.gradle.BuildExceptionReporter] Script 'C:\dev\trikorasolns\gradle-project\common.gradle'
 line: 46
00:54:38.948 [ERROR] [org.gradle.BuildExceptionReporter]
00:54:38.954 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
00:54:38.961 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating script.
00:54:38.966 [ERROR] [org.gradle.BuildExceptionReporter] > Project with path ':businessobjects' could not be found in root project
00:54:39.265 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.UnknownProjectException: Project with path ':bu
sinessobjects' could not be found in root project 'gradle-project'.

Line 46 of the common.gradle is project(’:businessobjects’){ :

// ############# PROJECTS ##############
  project(':businessobjects') {
  // Reporting
  apply plugin: 'project-report'

Thank you in advance for any help.

Best regards, António

(Peter Niederwieser) #2

How do you tell Gradle to use ‘hudson.gradle’? (’-b’ only works for single-project builds. For multi-project builds (and optionally also single-project builds), everything is controlled via ‘settings.gradle’.)

(jacob.costa) #3

Hi Peter,

Thank you for your answer.

I thought that, by executing the following statement at the home of the project I was launching my hudson.gradle script using my settings.gradle file.

gradle -b hudson.gradle -c settings.gradle

Nevertheless the following statement works.

gradle -b build.gradle -c settings.gradle

I think my settings.gradle file is being used because all my subprojects are being compiled. You can have a look at it (

If this is not the way to use a different build file, how can I accomplish this?

Thank you in advance.

Best regards, António

(Peter Niederwieser) #4

‘-b’ and ‘-c’ can’t be combined. If you use a ‘settings.gradle’, you have to declare the build script path(s) there. See ‘Settings’ in the Gradle Build Language Reference.

(Peng Xiao) #5

If -b and -c can’t be combined, an elegant error should be reported. I think a warning should also be reported when using -b for multiple project.