Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active October 30, 2021 17:16
Show Gist options
  • Save sfloess/5e3ad1fd25186cd841148d88e7f4f28a to your computer and use it in GitHub Desktop.
Save sfloess/5e3ad1fd25186cd841148d88e7f4f28a to your computer and use it in GitHub Desktop.
Maven Tips and Tricks

Maven

Helpful tips and tricks for Maven.

Quickies

  • Execute a java app: mvn exec:java -Dexec.mainClass=[fully qualified name of class]
  • Update properties: mvn -U versions:update-properties
  • PKIX path building failed: mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true ...
  • Proxies
    • http: -Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port>
    • https: -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>
  • Upload file: mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true deploy:deploy-file -DgroupId=o[Group ID] -DartifactId=[artifact ID] -Dversion=[Version] -DgeneratePom=true -Dpackaging=jar -DrepositoryId=[Repository I] -Durl=[URL] -Dfile=[Jar Filename] -DupdateReleaseInfo=true
    • mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true deploy:deploy-file -DgroupId=org.safehaus -DartifactId=jug -Dversion=2.0.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=redhat-nexus -Durl=https://foo.bar.com/nexus/myrepository/ -Dfile=jug-2.0.0.jar -DupdateReleaseInfo=true

Ignoring

  • certs: create a file ~/.mvn/maven.config:
-Dmaven.wagon.http.ssl.insecure=true
-Dmaven.wagon.http.ssl.allowall=true
-Dmaven.wagon.http.ssl.ignore.validity.dates=true

Skipping

  • javadocs: -Dmaven.javadoc.skip
  • Checkstyle: -Dcheckstyle.skip
  • Plugin Execution:
<build>
  <plugins>
    <plugin>
      <executions>
         <execution>
           <configuration>
             <skip>${maven.test.skip}</skip>
<build>
  <plugins>
    <plugin>
      <executions>
         <execution>
           <configuration>
             <skip>${skipTests}</skip>

RPM

When generating RPMs and including files, use the mapping parameter the sources element denoting the relative path and file name to include.

Examples

To include two files:

<build>
    <plugins>
        <plugin>
            ...

            <executions>
                <execution>
                    <goals>
                        <goal>rpm</goal>
                    </goals>
                </execution>
            </executions>
            
            <configuration>
                ...
                
                <mappings>
                    <mapping>
                         <sources>
                            <source>
                                <location>[relative dir 1]/[file 1]</location>
                            </source>
                        </sources>
                        ...
                    </mapping>
                    
                    <mapping>
                         <sources>
                            <source>
                                <location>[relative dir 2]/[file 2]</location>
                            </source>
                        </sources>
                        ...
                    </mapping>
                </mappings>
            </configuration>
        </plugin>
    </plugins>
</build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment