Hi,
I’m using gradle 4.8 in a multi-project java build for automating builds and deployments and I’m stuck in a “property set” problem.
In the root project build.gradle I apply a script to all subprojects:
[...] subprojects{ apply plugin: 'myTasks' apply from: 'build-generic.gradle' } [...]
In my build-generic I set some properties with default values:
project.ext { serverDomain = 'core' serverDeployPath = '/opt/'+serverDomain+'/deploy/' }
In myTasks plugin I define the deploy task:
project.task('deploy'){ doLast { def archive = '/build/libs/'+archiveName def serverDeployPath = project.properties.get('serverDeployPath') project.copy { from archive into serverDeployPath } } }
The idea is to override some of there properties in the build.gradle of a subproject, i.e.:
ext { serverDomain = 'services' }
But when I run the deploy task I alway get the file copied into /opt/core/deploy instead of /opt/services/deploy.
While I understand it does make sense, after reading, searching and experimenting I didn’t find how to comply with these points:
- serverDomain and serverDeployPath have to be defined with default values
- a subproject can redefine any of these properties
- if a subproject redefine serverDomain, serverDeployPath have to change accordingly
- redefining a property in a subproject have to be as simple as ext { prop = ‘value’ } (we have a lot of projects with script like that I change them all is not possible)
Is there a possibility to achieve what I want?
Thank in advance for every suggestion.