Hello
I have an old (very old) java web project (so ‘war’ plugin) that was previously built with ant. The project contains some files, that differ per environment, within resources/META-INF. With ant those files have just been copied and renamed with three different build tasks (local, dev, prod).
I have searched around a lot but I am not sure what would be the best practice way in up to date gradle versions to deal with such a setup. Copying around files does not feel like the gradle way especially as I would also have to deal with possible duplicates.
What I basically did so far (not sure if it was the best way):
- removed the files from resources/META-INF (so no duplicates to be placed from build)
- created three folders like e.g src/env/local; src/env/prod and placed the files in the proper folder removing env parts from file names; so files have the same name now but reside in different folders and there are no default files within META-INF currently to prevent duplicates when env specific files are copied there. A DuplicateStrategy to overwrite files would come in handy. But I think, that copying around files or having to deal with duplicates might be the sign of inproper usage of gradle tasks.
- register three tasks
['local', 'dev', 'prod'].each { env ->
tasks.register("buildWar${env.capitalize()}", War) {
from("src/env/$env") {
into('WEB-INF/classes/META-INF')
}
}
}
This basically works but the questions now are:
- Is this the best way to deal with?
- What about the behaviour of the default ‘war’ task?
– Should the default ‘war’ task be disabled? Will enable=false only prevent execution when callinggradle war? What about tasks that depend on war? - How to deal with maven-publish and artifactory publish to specify the correct build, e.g. I might only want to artifactory publish prod build. Do I have to create diffent publications for this also?
Right now I only have one mavenJava publication.
But I am definitely not sure whether this is the best approach. Because right now publishing would execute ‘war’-task and none of the specific task with the result that theWEB-INF/classes/META-INFfolder is empty because the default war task does not consider any env specific files fromsrc/envright now.
publishing {
publications {
mavenJava(MavenPublication) {
from components.web
}
}
}
Thx for any ideas!