Search code examples
jenkinsgradleivy

Jenkins and gradle - build projects with latest versions of dependencies for CI, specific versions for production


I am working with Jenkins, Gradle and our Ivy repository.

Our build scripts specify the exact version of dependencies to be used for the build. This is good practice for production.

For CI it would be interesting if the project build used the latest versions of our own libraries, that way we could not only see if library changes "broke the build" for the library but also if they broke the projects that use them. That seems to be the point of "integration"!

I understand that gradle will take "1.+" instead of "1.2.3" so I could hack the build.gradle for the project on the CI server to achieve this. But perhaps there is a neater way to do it (build script recognises it is in CI mode and uses latest and not specific versions, perhaps by running a sed script on build.gradle to change it).

Am I missing something in Jenkins or gradle? Are there any gradle plugins that achieve this, or alternative approaches that you have used to achieve this?


Solution

  • something alike this might work with Jenkins:

    if(System.getenv("BUILD_EXPERIMENTAL") == null) {
    
        // known to be stable versions       
        apply from: "dependencies.gradle"
    
    } else {
    
        // bleeding edge versions 
        apply from: "experimental.gradle"
    
    }
    

    this just would need the same project being set up twice, once with and once without environmental variable BUILD_EXPERIMENTAL, which is used to control which dependencies block is being applied.

    in case you want it generally being applied, when the project is being built with Jenkins, just replace BUILD_EXPERIMENTAL with BUILD_NUMBER (which by default is being set up in that environment).