androidmavenandroid-maven-plugin

how to use different denpendency in one project with maven?(android)


I use maven to package my app. Now I want integrate leakcanary only in debug version. So I need to add a <dependency> node to my pom.xml. But I want to remove it from release version. How Can I do that? I have a solution that a pom.xml for debug version and another pom for release version. Another solution is use shell to modify pom.xml before package. Any better idea?

maven:3.3.9
com.simpligility.maven.plugins:android-maven-plugin:4.4.3


Solution

  • You can do that with Maven profiles; they can host several POM elements: property values, configurations, dependencies, etc.
    You then enable one of more of these profiles with -P when running from the command line, or e.g. in Eclipse, with the specific entry in the Run as... window.

    Here's a brief example:

        <!-- Dependencies declarations -->
    </dependencies>
    
    <profiles>
        <profile>
            <id>extralib</id>
            <properties>
                <!-- specify property values here -->
            </properties>
    
            <dependencies>
            <dependency>
                <!-- add dependency decl here -->
            <dependency>
            </dependencies>
        </profile>
    
    <!-- you may have several profiles -->
    

    All of the childs of <profile> are optional.