I use dynamic dependencies and store the actual versions used in a property file to make the build reproducable. During rebuild i want to substitute the dynamic versions with the stored versions.
My problem is, that i cannot make the generated pom file to represent this substitution. I guess i´m missing some crucial basics in this scenario.
I would be grateful for any hints pointing me in the right direction.
task ('rebuild') {
description 'Rebuilds the project using rebuild.properties.'
group 'Build'
}
boolean isRebuild = false // Don´t save rebuild properties on rebuild
project.gradle.startParameter.taskRequests.each { Object object ->
if(object instanceof TaskExecutionRequest ) {
((TaskExecutionRequest ) object).getArgs().each { String arg ->
if(arg.compareTo('rebuild') == 0) {
isRebuild = true
}
}
}
}
if(!isRebuild) {
task('saveRebuildProperties', type: SaveRebuildPropertiesTask) {
description 'Saves the version properties to rebuild.properties'
group 'Build'
}
compileJava.dependsOn('saveRebuildProperties')
}
if(isRebuild) {
File rebuildPropertiesFile = project.rootProject.file('rebuild.properties')
Properties rebuildProperties = new Properties()
if(rebuildPropertiesFile.exists()) {
FileInputStream input = new FileInputStream(rebuildPropertiesFile)
rebuildProperties.load(input)
input.close()
if(rebuildProperties.getProperty('version').compareTo(project.version.toString()) == 0) {
project.configurations.all { Configuration configuration ->
configuration.resolutionStrategy.eachDependency { DependencyResolveDetails details ->
String key = "${details.requested.group}:${details.requested.name}"
String value = rebuildProperties.getProperty(key, null)
if(value != null) {
details.useVersion value
project.logger.quiet("Configuration ${configuration.name}: ${key} set to version ${value} (Rebuild).")
}
}
}
} else {
project.logger.error('The version of the rebuild.properties file does not match with the checked out version of the source! Reverting to current properties.')
}
} else {
project.logger.error('The rebuild.properties could not be loaded! Reverting to current properties.')
}
}
publishing {
publications {
maven(MavenPublication) { from components.java }
}
}
model {
tasks.generatePomFileForMavenPublication {
dependsOn 'compileJava'
}
}