0

I'm migrating from Maven to Gradle 4.4. There was several maven profiles with such sections:

<properties>
   <module.suffix>-14</module.suffix>
   <wildfly.hostname>10.***.***.14</wildfly.hostname>
</properties>

There are a lot of ${module.suffix} in several resource files such as .xml, .properties and etc. I was able to run mvn wildfly:deploy -Pdeploy-14 and got my war deployed with correct suffixes in all files. The problem is: how to do the same in Gradle? I'm new to Gradle but I believe it is modern powerful tool, it must be able to do this with ease. Help, please.

P.S. The next step of my migration will be setting up the Gradle Wildfly plugin. I didnt try it yet, so if you have any useful advices please welcome.

Gradle task replace string in .java file didn't help (I tried all of the answers, but not sure I did it right).

UPD. When I try do to this

processResources {
    def params = [moduleSuffix: 'moduleSuffix']
    from 'src/template/resources', {
        expand params
    }
}

the expand word is underlined and IDEA says "Cant resolve symbol 'expand'"

2 Answers2

0

I'm not sure about what the Wildfly plugin handles as far as substitution, but in general the Copy task type can handle most substitutions via the expand method. The default processResources task from the Java plugin is this type so substituting values into resources can be done by modifying the task like so (basic example):

processResources {
    expand project.properties
}
Kiersten Arnold
  • 1,840
  • 1
  • 13
  • 17
0

If it were me, I'd avoid extra "work" by putting these "template" resources in src/template/resources. That way the majority of resources wouldn't need to be parsed to find the ${...} placeholders. Then, as @ChrisArnold suggests you could use the expand(Map) method on the processResources task.

processResources {
    from 'src/template/resources', {
        expand project.properties
    }
}
lance-java
  • 25,497
  • 4
  • 59
  • 101
  • I'm doing something wrong. After I change this task and run clean build, I see `:processResources UP-TO-DATE 1ms`. And no resource files appear in build dir or in .war file. – Pavel Krizhanovskiy Dec 16 '17 at 04:36