Search code examples
androidmavenandroid-buildandroid-maven-plugin

android-maven-plugin: Binding proguard to later phase


In my maven build, I'd like to execute the proguard goal after the tests, in order to get test result faster. Therefore, I tried to bind it to prepare-package phase. However, my config bellow does not have any effect. The proguard goal is still executed in process-classes phase (default-proguard). What am I missing?

<plugin>
    <groupId>com.simpligility.maven.plugins</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>4.1.0</version>
    <executions>
        <execution>
            <id>progurad-after-test</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- ... -->
        <proguard>
            <skip>false</skip>
        </proguard>
    </configuration>
</plugin>

Solution

  • Old answer:

    You can not change the phase proguard runs. But typically you can isolate into a profile to only run when needed and not with each build. The typical use case would be a release profile that you only run for releases. You could also make it part of a QA profile and use that for development builds that need to be verified beyond the normal usage during development.

    Update after some thinking:

    You can change the proguard mojo execution to a different phase by having two executions configured. One for the process-sources phase as originally configured inside the Android Maven Plugin set to be skipped. Then the second execution is configured for the desired phase with skip set to false.

    <plugin>
        <groupId>com.simpligility.maven.plugins</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>4.1.0</version>
        <executions>
            <execution>
                <!-- Skip proguard in the default phase (process-classes)... -->
                <id>override-default</id>
                <configuration>
                    <proguard>
                        <skip>true</skip>
                    </proguard>
                </configuration>
            </execution>
            <execution>
                <!-- But execute proguard after running the tests
                     Bind to test phase so proguard runs before dexing (prepare package phase)-->
                <id>progurad-after-test</id>
                <phase>test</phase>
                <goals>
                    <goal>proguard</goal>
                </goals>
                <configuration>
                    <proguard>
                        <skip>false</skip>
                    </proguard>
                </configuration>
            </execution>
        </executions>
        <configuration>
            <!-- Other configuration goes here. -->
        </configuration>
    </plugin>