Gradle run configurations with various properties

Here are 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 is: how do I configure a different execution task to use different jvm arguments, for example: -Dgreeting.language = ch.

I switched to gradle from maven, so for this case I would use maven profiles. Is there any structure in gradle that matches profiles?

UPDATE 1

Let me clarify the problem a bit. My project is much more complicated than I cited above. I would like to have a set of gradle tasks (or profiles / or what it called in gradle), each task should be self-contained with a custom set of variables. As an output, I would like to have a gradle task set:

 gradle <enableAllFeatures> gradle <disableFeatureA> ... 

These variables do not have to be JvmArgs. It can be constants (or everything possible in gradle), but it is a requirement to have different tasks , and each task should specify its own set of variables

UPDATE 2

I surfed the Internet and found out a very interesting topic - gradle build options , but it seems to only apply to android projects. Is it possible to use build options in java projects?

+5
source share
1 answer

Parameterize the language as follows:

 applicationDefaultJvmArgs = ["-Dgreeting.language=${language}"] 

Then, when you start Gradle, pass the language as a parameter using the -P option:

 $ gradle -Planguage=en tasks 

or

 $ gradle -Planguage=ch tasks 

References

Gradle Domain: Using Properties for Multiple Environments or Profiles

Similar profile to Maven Gradle

+2
source

Source: https://habr.com/ru/post/1211636/


All Articles