Define System Parameter for each subproject

buildship

(Andreas Houben) #1

Hi there, in my current project I need to set a system parameter to define the repository in which to release into.

I use some logic to determine from a version number the value of the boolean “isRelease”, which then sets the release repository

submodules{
isRelease = someCodeToDetermineIsRelease() 
if (isRelease) {
        System.setProperty("releaserepo", "myReleaseRepository")
    } else {
        System.setProperty("releaserepo", "mySnapshotRepository")
    }
} 

For example:
1.0.0 --> release
1.0.0.SNAPSHOT --> snapshot

This works so far but:

This logic is placed in a common build.gradle that is shared between multiple submodules.

parent
+ - submodule1 
+ - submodule2
+ - submodule3

Now when I run gradle clean build from parent, the configuration part runs before gradle starts building the modules.

Meaning that only the last version number counts for my configuration. Instead I want to run my configuration code before every submodule.

Example:

parent
+ - submodule1 1.0.0.SNAPSHOT 
+ - submodule2 1.0.0.SNAPSHOT
+ - submodule3 1.0.0

How it currently works:
All modules go to release because last one is not .SNAPSHOT

How I want it to be
submodule1 and submodule2 go to snapshot
submodule 3 goes to release.

Any advice?


(Andreas Houben) #2

I solved it myself using tasks. My main mistakes was, that I defined tasks without the << therefore they did not run when I configured them via dependsOn but at the beginning of the build process.


(Stefan Oehme) #3

Instead of using system properties, the canonical way would be to use either Extra Properties or just configuring the publishing of the subprojects directly.

A system property is global to your whole build, so you can’t configure it “per subproject”.


(Andreas Houben) #4

I understand that. The thing is, I have to configure another build tool (bndtools) that executes the release for me and for that I need system properties.


(Stefan Oehme) #5

There’s a bnd tools Gradle plugin.

In general if you use another tool, you should fork it with a JavaExec task and pass the system properties there.


(Andreas Houben) #6

I know, we already use the gradle plugin. Unfortunately there’s no switch for what I need. I talked to the bnd guys here: https://groups.google.com/forum/#!searchin/bndtools-users/release/bndtools-users/5VFHAr2_ZHU/gCDXO0LHBAAJ

To fork and change the gradle plugin, i fear my gradle skills aren’t sophisticated enough.


(Stefan Oehme) #7

I didn’t mean fork the code, I meant fork a new process so you can set system properties :slight_smile:

If the bnd plugin doesn’t allow that then pushing for an improvement there seems like the best idea.


(Andreas Houben) #8

I will look into both suggestions, once I find the time. Thanks so far :slight_smile: