maven - How to specify Spring propertyPlaceHolderConfig values in Gradle build? -
i migrating existing maven build gralde , facing issue. in maven pom.xml ,spring propertyplaceholderconfig values specified in maven profiles. maven build specifies 3 types of profiles dev,test , prod
i want achieve same thing in gradle build till not able figure out how in gradle
thanks, manoj
i think there different options how can model existing mvn profiles gradle. i'll give 1 example here:
given have property file looks that:
property1=$prop1 //prop1 , prop2 placeholder environment specific values property2=$prop2 now can model profiles in build.gradle file:
def profileproperties = [ test:[prop1:"testvalue1", prop2:"testvalue2"], dev:[prop1:"devvalue1", prop2:"devvalue2"], prod:[prop1:"prodvalue1", prop2:"prodvalue2"] ] this ordinary nested map defined in groovy.
by passing commandline option 'profile' gradle call
gradle clean build -pprofile=dev you can pass gradle project environment you're in. in build script can differentiate adding following build file:
def usedprofile = project.getproperty("profile") processresources{ expand(profileproperties[usedprofile]) } this takes defined profileattribute , reads according map of environment properties. environment properties passed map expand filter method, part of gradle api. have @ http://gradle.org/docs/current/dsl/org.gradle.api.tasks.copy.html#org.gradle.api.tasks.copy:expand(java.util.map) details expand method.
the whole build.gradle file simple java project this:
apply plugin:'java' def profileproperties = [ test:[prop1:"testvalue1", prop2:"testvalue2"], dev:[prop1:"devvalue1", prop2:"devvalue2"], prod:[prop1:"prodvalue1", prop2:"prodvalue2"] ] def usedprofile = project.getproperty("profile") processresources{ expand(profileproperties[usedprofile]) } this draft, of course can use groovy goodness here add bit more logic here, having default profile, etc.
hope helps,
regards, rené
Comments
Post a Comment