how to add multiple build configurations for my plugin?

已回答

Hello, I use ./gradlew clean build to build my plugin. I want there to be 2 diff configurations for build, i.e - prod(production) and dev(development) and I would want to execute some command like ./gradlew clean build prod to build for production. 

In some files, I want to write some code like 

If(build.isEquals("prod")) {

} else {

 

0

Hi,

You can use properties like “dev” and “prod” passed to ./gradlew command like ./gradlew -Pdev … or  ./gradlew -Pprod …. In your build script, use:

if (project.hasProperty("dev")) {
  // do something dev specific
}
if (project.hasProperty("prod")) {
  // do something production specific
}
0

I didn't understand it. I want to have two separate logic in a Java file. So, from build.script file, i need to store the build configuration and access it wherever I want. how to achieve this?

0

I misunderstood that you want to achieve it in the plugin build script.

I suggest searching for information about Gradle resource filtering. See e.g., https://stackoverflow.com/questions/25328132/is-resource-filtering-in-gradle-possible-without-using-tokens

You can store the information about the environment in some properties file in the resources folder and access it at runtime. This file should hold a placeholder for the environment value, which will be replaced with actual value during the build.

0

Hello, I am using ./gradlew clean build -DbuildType="prod" but when I do System.getProperty("build type") it returns null 

0

Hi, your property name is buildType, but you fetch build type. These are different values.

0

this might be a typo here. in my program I was using correct name. Is this because there is no main class in my plugin?

0

Do I have to mention smthg in my build.gradle.kts file? 

0

请先登录再写评论。