I would like to pass deployDir
(with value /my_archive
) to uploadArchives
task in my_project
:
task build (type: GradleBuild) {
buildFile = './my_project/build.gradle'
tasks = ['uploadArchives']
/* startParameter = [deployDir:"/my_archive"] ??? */
}
I do not know how to declare the start parameters. I have tried different ways, e.g.,
startParameter = [deployDir:"/my_archive"]
Without success.
How to declare startParameter in the GradleBuild task?
Types of Input Arguments When we want to pass input arguments from the Gradle CLI, we have two choices: setting system properties with the -D flag. setting project properties with the -P flag.
Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.
I assume you mean to pass the deployDir
as a project property. In this case, you'll find there is a setProjectProperties(Map)
method you can use:
task build (type: GradleBuild) {
buildFile = './my_project/build.gradle'
tasks = ['uploadArchives']
startParameter.projectProperties = [deployDir: "/my_archive"]
}
This will enable you to access deployDir
as a variable from the called build script:
uploadArchives {
repositories {
mavenDeployer {
repository(url: deployDir)
// --- or, if deployDir can be empty ---
repository(url: project.properties.get('deployDir', 'file:///default/path'))
}
}
}
we can set the project properties and system properties via the api
setProjectProperties(Map<String,String> projectProperties)
setSystemPropertiesArgs(Map<String,String> systemPropertiesArgs)
here is the sample from my local for startParameter:
task startBuild(type: GradleBuild) {
StartParameter startParameter = project.gradle.startParameter;
Iterable<String> tasks = new ArrayList<String>();
Iterable<String> excludedTasks = new ArrayList<String>();
startParameter.getProjectProperties().each { entry ->
println entry.key + " = " + entry.value;
if(entry.key.startsWith('t_')){
tasks << (entry.key - 't_');
}
if(entry.key.startsWith('build_') && "true" == entry.value){
tasks << (':' + (entry.key - 'build_') +':build');
}
if(entry.key.startsWith('x_') && "true" == entry.value){
excludedTasks << (entry.key - 'x_');
}
}
startParameter.setTaskNames(tasks);
startParameter.setExcludedTaskNames(excludedTasks);
println startParameter.toString();
}
we can reference the api from this link StartParameter
the startparameter is really powerful in gradle when you need to customize your gradle build logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With