Intellij make build maven resources filtering

I've been trying to use IntelliJ IDEA CE 11.1 (#IC-177.177) to do resources filtering for my Android project.

If I compile the android app using maven directly "mvn clean package", resource filtering is applied successfully to my final apk.
If I build the android app using the Intellij make process, the resources that gets packaged in the apk don't get filtered.

For example if I had a app.properties file under "src/main/resources" with this content, it doesn't get replaced by intellij build process but
works perfectly with maven.

app_version ${version}


I know the build process for IntelliJ is a bit different than maven but I'm not entirely sure where it differs.
Am I doing something wrong here or is this an issue?

Maven pom used:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.lixar.filtering</groupId>
    <artifactId>filtering-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>filtering-app</name>

    <properties>
        <platform.version>2.3.3</platform.version>
    <app.name>filtering-app</app.name>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
          <sourceDirectory>src/main/java</sourceDirectory>
           <resources>
                <resource>
                     <directory>src/main/resources</directory>
                     <filtering>true</filtering>
                     <includes>
                          <include>*.properties</include>
                     </includes>
                </resource>
           </resources>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <platform>10</platform>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4 comments
Comment actions Permalink

Resource filtering in maven is performed by the resource plug-in. IDEA has no direct mapping for that functionality that would allow it to do such filtering and token replacement. While IDEA's build abilities are a bit more robust than simply compiling code, it is in the end an IDE and not a build system like Ant, Maven, or Gradle. So if your build requirements are more than basic, it's best to leave the work to those tools. Since you are configured to use maven, just do all your builds via maven. You can run it right from within IDEA. Is there a reason why you need to use the IDEA make command? Note that run/debug configurations, including ones for unit tests, can be configured to run a maven goal rather than the IDEA make prior to running.

0
Comment actions Permalink

Hi Mark,

Thanks for taking the time to answer my question.  The differences between IntelliJ make command an the maven is a bit clearer now.  The reason that I was actually trying to use the IntelliJ make command process was because I wasn't aware that I could get a run / debug configuation running though IntelliJ while still using maven.  I've only been using maven for a few months now and IntelliJ for a few weeks.

If I'm trying to achieve this for Android, the idea would be that maven is used for the build portion.  It would generate the apk and then IntelliJ would come in and use it to launch the application on a device or emulator for debugging.  Do I have this right?

Would you happen to know where I could get a good example of how to acheive this?

Thanks again for the help

0
Comment actions Permalink

Alright so I had time to do a little bit of testing and I think I was able to figure out most of the changes that I needed to do to get this working.

I created a run configuation for "Android Application" and I simply unselected the "Make" option from the "Before Launch" section in the "General" tab.  I then simply checked the "Run Maven Goal" and then went and browsed and selected the "Package" lifecycle.  The package lifecyle seems to take care of the full process from generating resource to building the apk, seemed like the right one to choose from.

The only other thing that I needed to change what the name of the "APK" to run when launching the app from IntelliJ.  Since maven by default will append the "-XX-SNAPSHOT.apk" to your apk, IntelliJ wasn't finding my apk.  I did that from the "Facet" section in the project configuation window under the "Compiler" tab.

And voila!

0
Comment actions Permalink

I've followed your answer with a little change.
I'm running a J2EE under tomcat, I've removed Make and added Clean and Package before deploy and everything is running fine

0

Please sign in to leave a comment.