Here is my inputs:
Main.java
package com;
public class Main {
public static void main(String[] args) {
System.out.println(System.getProperty("greeting.language"));
}
}
build.gradle
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.7
version = '1.0'
mainClassName = "com.Main"
applicationDefaultJvmArgs = ["-Dgreeting.language=en"]
My question: How can I configure another run task configuration to use different jvm arguments, for example: -Dgreeting.language=ch.
I moved to gradle from maven, so for such case I would use maven profiles. Is there any strucrure in gradle which corresponds to profiles?
UPDATE 1
Let me clarify a task a little bit. My project is far more complex that example I gave above. I would like to have a set of gradle tasks(or profiles/or whatever it's called in gradle), each of the task should be self-contained with custom set of variables. As an output I would like to have set of gradle task:
gradle <enableAllFeatures>
gradle <disableFeatureA>
...
It is not a requirement for these variables to be JvmArgs. It could be constants(or whatever possible in gradle) but it is requirement to have different tasks, and each task should specify it's own set of variables
UPDATE 2
I was surfing internet and found out very interesting topic - gradle build variants, but it is seems to be applicable only to android projects. Is it possible to use build variants in java projects?
Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.
Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.
A multi-project build in Gradle consists of one root project, and one or more subprojects. This is the recommended project structure for starting any Gradle project. The build init plugin also generates skeleton projects that follow this structure - a root project with a single subproject.
Parameterize the language like this:
applicationDefaultJvmArgs = ["-Dgreeting.language=${language}"]
Then when you run Gradle, pass the language as a parameter using the -P option:
$ gradle -Planguage=en tasks
or
$ gradle -Planguage=ch tasks
References
Gradle Goodness: Using Properties for Multiple Environments or Profiles
Similar Maven profile Gradle
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