How to handle situation when build.gradle and source tree aren't together?

(Don Henry) #1

I want to be able to run gradle in the situation where the build.gradle file is not located with the source tree that it’s using for the build. For my experimenting, it looks like both the “-b” and “-p” point to the folder where build.gradle is located. I need some way to identify where the source tree lives.

This need arise when setting up a gradle build within Jenkins. The source tree will be within the Jenkins folder structure and build.gradle will be within a build tree located somewhere else.

(Peter Niederwieser) #2

Can you elaborate on why you have this need? It isn’t common.

(Don Henry) #3

The back story…

I am moving our build process from ANT to gradle. The goal is to port all of the current functionality over. One of the current functions is to pull the source code from our SVN repository, so the ANT build.xml file cannot be in the same tree as these source files. What a developer normally does is pull the “empty” build tree down, then start to fill in the nodes with source files as he works on various projects.

With Jenkins, mixing the build scripts in the same folder with the source files is not possible because the Jenkins jobs and the associated source files are within the Jenkins tree. So we have the situation where we have to tell ANT where the source files are (with a property) and where the build.xml file is (with the “-f” option). As I type this, it occurred to me that I could the same thing with gradle. I had thought I could just run gradle in the folder where the source lives, but that didn’t work. I’ll try the approach I used with ANT.

In the meantime, if you think I’m missing something or have a better solution, let me know. Thanks.

(Don Henry) #4

My solution appears to work.

I make these changes to build,gradle:

// The test files are in the same folder as the JAR files, so we have to override the gradle conventions {
    srcDirs = ["$moduleDir/javasource"]
    exclude '**/*Test*'
    exclude '**/*Mock*'
} {
    srcDirs = ["$moduleDir/javasource"]
    include '**/*Test*'
    include '**/*Mock*'

Then I can put build.gradle in some other folder and run this gradle command from a third location:

C:\test>gradle -b c:\bps_build\projects\build.gradle -PmoduleDir=c:\bps_build\projects\mscore clean compileTestJava

What is puzzling to me is that the “-b” and “-p” options essentially do the same thing - identify the location of build.gradle. A useful command line option would be one that identifies the location of the folder that contains the source that build.gradle works on. This would allow me to backup a level and not have to deal with these subfolders on a case by case basis.