Wednesday, May 27, 2015

Maven stuff

First off, here is a page that contains some global maven properties. Some best practices.

  • Deploy lib to local maven repo
    mvn install:install-file -Dfile=target/eyjafjalla.apklib -DgroupId=com.example -DartifactId=eyjafjalla -Dversion=1 -Dpackaging=apklib
    

  • Running maven with profiles:
    mvn groupId:artifactId:goal -P profile-1,profile-2
    

  • Deactivating profiles:
    mvn groupId:artifactId:goal -P !profile-1,!profile-2
    
    This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config.

  • Available properties:
    mvn help:system
    

  • By default run all tests, but this can be disabled:
    <profile>
        <id>by_default_run_all_tests</id>
        <activation>
            <property>
                <name>!notest</name>
            </property>
        </activation>
        <properties>
            <notest>false</notest>
        </properties>
    </profile>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <skip>${notest}</skip>
            <skipTests>false</skipTests>
        </configuration>
    </plugin>
    
    Run with
    mvn install -Dnotest
    Related stackoverflow question

  • Or more generic default overridable parameter:
    <profile>
        <id>by_default_copy_poker_assets</id>
        <activation>
            <property>
                <name>!noassetoverwrite</name>
            </property>
        </activation>
        <properties>
            <overwrite_poker_asset>true</overwrite_poker_asset>
        </properties>
    </profile>
    
    <profile>
        <id>do_not_copy_poker_assets</id>
        <activation>
            <property>
                <name>noassetoverwrite</name>
            </property>
        </activation>
        <properties>
            <overwrite_poker_asset>false</overwrite_poker_asset>
        </properties>
    </profile>
    

  • Execute shell command:
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
            <execution>
                <id>some-execution</id>
                <phase>validate</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>python</executable>
            <workingDirectory>${project.basedir}/..</workingDirectory>
            <arguments>
                <argument>~/Rockaway/file_date_check/file_date_check.py</argument>
            </arguments>
        </configuration>
    </plugin>
    

  • No comments: