Maven profile resources + Eclipse and Tomcat - Eclipse bin output dir does not have the filtered config files in build dir


(nicolas.fabre) #1

Hi,

I need to replace some tokens in the file /src/main/resources/application.properties of my java project according to a targeted environment (to hit a Test or a Prod database for example). With Maven I managed that with Maven resources and profiles corresponding to my targeted environments. I succeeded to get the same behavior with Gradle by using the conf below and running gradle build -Pprod (for prod env for example).

if (project.hasProperty("test")) {
   processResources {
    filter ReplaceTokens, tokens: [
     gradle_environment : 'TEST'
   ]
   }
  println "TEST";
 } else if (project.hasProperty("prod")) {
      processResources {
    filter ReplaceTokens, tokens: [
     gradle_environment : 'PROD'
   ]
   }
  println "PROD";
 } else {
  println "NO";
 }

But when I import the project in Eclipse after having executed gradle eclipse, it seems that the tokens are not replaced (I get some errors complaining about values corresponding to the non converted/filtered tokens in my property file). However, when I look to the file in /build/resources/main/application.properties, the file do have the correct values instead of tokens. But it seems that Eclipse consider the files under the /bin directory : /bin/application.properties where the tokens are not filtered.

How can I make Eclipse considering the filtered application.properties file so that the code launched with Eclipse (Junit or webapp running in Eclipse embedded Tomcat) use the filtered values instead of token placeholders ?

Thank you