We have a multi-module java project with inter-module dependencies and use Gradle for our build.
We have setup an Azure CI YAML pipeline for running our long running integration tests. The integration test task for each module is run in its own stage and each stage runs on a different agent (so we can parallelise the stage runs).
Now because of the inter module dependencies, we find that we compile most of the same code for each module's run. So to reduce the need for this repeated compilation, I want to have a specific stage for compiling the code, publish the compiled code and then let the downstream stages download the compiled code and just run the tests.
The YAML code looks something like this:
stages:
- stage: Compile_Source
dependsOn: []
jobs:
- job: Windows
pool:
vmImage: 'windows-latest'
steps:
- checkout
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'integrationTestClasses' # this will compile all code
- task: PublishPipelineArtifact@1
displayName: Publish compiled code
inputs:
targetPath: '$(Build.BinariesDirectory)'
artifact: 'CompiledCode'
publishLocation: 'pipeline'
- stage: ModuleOne
dependsOn: Compile_Source
jobs:
- job: Windows
pool:
vmImage: 'windows-latest'
steps:
- checkout
- task: DownloadPipelineArtifact@2
displayName: Download Compiled Code
inputs:
buildType: 'current'
artifactName: 'CompiledWindowsCode'
targetPath: '$(Build.BinariesDirectory)'
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'module_one:integrationTest'
However what I'm finding is the call of module_one:integrationTest
in the ModuleOne
stage still compiles all the code whereas what I'm hoping to get is it should should say up-to-date
for the compilation task.
Is my objective feasible and if so what am I missing?
You can consider using the Gradle Build Cache.
Steps:
org.gradle.caching=true
to the gradle.properties
file.You can read this Enabling the Gradle Build Cache and Share results between CI builds for more details.