Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does IntelliJ's Maven filtering support work?

I have noticed when you configure a Maven project to use property filtering the property filtering seems to also work during a non-maven IntelliJ "make". This means the IntelliJ run configurations for Jetty/Tomcat/GWT/Glassfish will still honour your maven resource filtering.

So if I add this to my pom.xml:

 <build>
     <resources>
         <resource>
             <directory>src/main/resources</directory>
             <filtering>true</filtering>
             <includes>
                 <include>**/*.properties</include>
                 <include>**/persistence.xml</include>
             </includes>
         </resource> ....

It should filter any properties in my properties and peristence.xml files before any intellij run configurations start. This is very usefull for swapping in JDBC references or filesystem parameters.

The only problem I am having is that IntelliJ only seems to honour filtering in src/main/resources even if I change pom.xml to have a second entry for other directories (ie:src/integrationtest/resources).

This all seems to be "automagical". So how does it work and where (if anywhere) can I configure it?

like image 376
benstpierre Avatar asked Apr 05 '12 21:04

benstpierre


2 Answers

IntelliJ IDEA's Make features are capable of filtering Maven resources. However, IntelliJ IDEA yet does not support filtering web resources.

source: http://www.jetbrains.com/idea/webhelp/maven.html#compile
No further details about this support in whole intellij webhelp though, so I guess it should work just like maven's process-resources phase does.

The problems you are having can be caused by the fact that directory src/integrationtest/resources doesn't follow maven conventions. Maybe it will work if you:

  • make it src/test/resources/integrationtest/

or

  • configure maven to respect src/integrationtest as test sources (but if integrationtest isn't well-known convention it will be violation of maven's COC rule)

or

  • make it another maven (sub)module, if you want to emphasize isolation of integrationtest

As for filtering directories different that src/main/resources: filtering src/main/webapp/META-INF worked out-of-a-box for me.
(Maven 3.0.4, Intellij 12.1.4)

like image 169
vucalur Avatar answered Oct 20 '22 05:10

vucalur


Good news, looks like the issue will be fixed in 13.1

http://youtrack.jetbrains.com/issue/IDEA-25934

EDIT: Sorry if not clear enough, the bug case is just marked as "fixed" with no further explanation... But I tested in 13.1 EAP version (build 134.1445) and while previously IntelliJ would overwrite the resources, it now preserves the web resources filtered by Maven.

like image 26
Nico Avatar answered Oct 20 '22 07:10

Nico