Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins builds with gradle subprojects

Is there anyway I can create a two module projects in gradle, and trigger a build for each module by itself?

Root project 'Example' 
    Jenkinsfile
\--- Project ':SubProject'
    Jenkinsfile

I want that jenkins will trigger a build only in the module that has been changed.


for example :

If my SubProject changed, then only SubProject will execute it's own Jenkinsfile.

I looked up for this option for a very long time...

As you can see in the other questions, there is no any easy way to achieve that.

Is there any Jenkins pipeline or plugin that can deal with that?

like image 267
Daniel Taub Avatar asked Jan 30 '18 19:01

Daniel Taub


People also ask

What is subprojects in Gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency.

How do I run a Gradle build in Jenkins?

Create a Jenkins job Enter a new name for the project. We'll pick "gradle-site-plugin" for the project. Select the radio button "Git" in the section "Source Code Management". Enter the URL of the GitHub repository: https://github.com/gradle/gradle-site-plugin.git .

Does Jenkins support Gradle?

It is the official build tool for Android. Gradle provides integration with several development tools and servers, including Eclipse, IntelliJ, Jenkins, and Android Studio.


1 Answers

  • It is relatively easy to only invoke the gradle tasks from a given subproject:
    • To build Example: ./gradlew :build
    • To build SubProject: ./gradlew :SubProject:build
    • Gradle will then only run the task graph these invocation define.
  • It should be relatively easy to setup two different jobs in Jenkins, based on distinct Jenkinsfile, and each could have the custom invocation defined above.

However, the triggering of one project only will most likely be the tricky thing as they most likely live in the same source control location.

Maybe the easy fix is also to have them decoupled, using svn:externals or Git submodules.

like image 93
Louis Jacomet Avatar answered Oct 08 '22 22:10

Louis Jacomet