I have a problem with Azure devops Pipeline using Java Maven and caching. When I change a file in a custom dependency then the Cache is not updated by Azure devops.
I use Azure devops artifacts to store the created artifacts.
I have a basic Java Application we call it: nl.mycompany.toolA
I have a dependency with the name: nl.mycompany.dependencyB
The Dependency nl.mycompany.dependencyB is included via the pom.xml in the basic Java application
This is my Azure devops pipeline code:
# Maven
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
pool:
vmImage: ubuntu-latest
steps:
- task: DownloadSecureFile@1
name: settings_xml
displayName: Download settings.xml
inputs:
secureFile: 'settings.xml'
- task: Cache@2
inputs:
key: 'maven | "$(Agent.OS)" | **/pom.xml'
restoreKeys: |
maven | "$(Agent.OS)"
maven
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'deploy'
options: '-s $(settings_xml.secureFilePath)'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
My dependency nl.mycompany.dependencyB has a file: sharedModule/cdm.dwl which very often has to be updated.
First I build my basic Java app with Azure Devops pipeline, with the code above and the inserted Junit tests run fine.
Then I update the cdm.dwl file in the dependency Then I build the dependency with Azure devops with the code above.
Then I build the basic Java app with Azure devops again and the Junit test run fine again but they should give an error because the cdm.dwl file has changed.
When I download the JAR file and check the content the included dependency does not have the updated cdm.dwl file, so the cache is NOT updated by Azure devops.
When I remove the Cache@2 task in the pipeline yaml file then there is no problem at all.
How can I fix this ?
CodePudding user response:
I have found a solution for this problem thanks to a coleague of mine: Changes this line in the script above:
goals: 'deploy'
in this line:
goals: 'deploy -U'
Will do the job, because it forces Maven to Update the dependencies.