Maven mixin for the "standard" set of plugins.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.adoc
bumpver.sh
pom.xml
release.sh

README.adoc

java-mavenmixin-standard

This module provides a maven mixin that can be incorporated into Maven module, defining standard versions and configuration for the clean, resources, compiler, jar, install, deploy and site plugins. This reduces the size of the maven pom.xml file for that consuming module; it simply needs to reference this module using the mixin-maven-plugin.

Tip

All of these plugins are also defined within the Maven "super pom" (part of the Maven install), so strictly speaking there is no need to define these modules. However, relying on the super pom definitions is not good practice; the versions of those plugins will vary with the version of Maven installed, so can result in non-repeatable builds. This maven mixin allows the version of all of these plugins to be fixed in a single statement.

The appropriate configuration is included in a <profile> which is automatically included in all builds. This profile can be disabled using a Maven property.

Note

This module was initially developed for use within Apache Isis applications but can be used by any Java application.

How to Configure

To configure:

  • specify the plugin versions.

    There’s an easy way, or a more long-winded way:

    • For the easy way, simply inherit from the appropriate version of incodehq:incode-build.

    • For the long-winded way, copy and paste the following into either the pom.xml of the consuming module or (better still) the pom.xml of the top-level parent of the consuming module:

      <properties>
          ...
          <mavenmixin-standard.version>0.0.4</mavenmixin-standard.version>
      
          <maven-clean-plugin.version>2.5</maven-clean-plugin.version>
          <maven-project-info-reports-plugin.version>2.9</maven-project-info-reports-plugin.version>
          <maven-resources-plugin.version>2.6</maven-resources-plugin.version>
          <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
          <maven-jar-plugin.version>2.4</maven-jar-plugin.version>
          <maven-install-plugin.version>2.5.1</maven-install-plugin.version>
          <maven-deploy-plugin.version>2.8.1</maven-deploy-plugin.version>
          <maven-site-plugin.version>3.3</maven-site-plugin.version>
          ...
      </properties>

      and:

      <build>
          <pluginManagement>
              <plugins>
                  ...
                  <plugin>
                      <artifactId>maven-clean-plugin</artifactId>
                      <version>${maven-clean-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-project-info-reports-plugin</artifactId>
                      <version>${maven-project-info-reports-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-resources-plugin</artifactId>
                      <version>${maven-resources-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>${maven-compiler-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-jar-plugin</artifactId>
                      <version>${maven-jar-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-install-plugin</artifactId>
                      <version>${maven-install-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-deploy-plugin</artifactId>
                      <version>${maven-deploy-plugin.version}</version>
                  </plugin>
                  <plugin>
                      <artifactId>maven-site-plugin</artifactId>
                      <version>${maven-site-plugin.version}</version>
                  </plugin>
                  ...
              </plugins>
          </pluginManagement>
      </build>
  • add the following to the pom.xml of the consuming module:

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.odavid.maven.plugins</groupId>
                <artifactId>mixin-maven-plugin</artifactId>
                <version>0.1-alpha-39</version>
                <extensions>true</extensions>
                <configuration>
                    <mixins>
                        <mixin>
                            <groupId>com.danhaywood.mavenmixin</groupId>
                            <artifactId>standard</artifactId>
                            <version>${mavenmixin-standard.version}</version>
                        </mixin>
                    </mixins>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • as a property, specify the artifact’s Java 9 module name:

    <properties>
        <jar-plugin.automaticModuleName>com.mycompany.myapp.foobar</jar-plugin.automaticModuleName>
    </properties>
  • optionally, update the following properties in the consuming module’s pom.xml:

    <properties>
        <compiler-plugin.source>1.8</compiler-plugin.source>
        <compiler-plugin.target>1.8</compiler-plugin.target>
        <compiler-plugin.compilerArgument>-parameters</compiler-plugin.compilerArgument>
    </properties>

    The values shown are the defaults, so these properties need only be defined if you require different values.

If you are using git, you might also want to configure the git-commit-id-plugin to populate the ${git.commit.id.abbrev} property. This will then be included within the jar’s manifest (META-INF/MANIFEST.MF) as the SCM-Revision property. For example:

<plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <version>2.2.3</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>validate</phase>
        </execution>
    </executions>
    <configuration>
        <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
    </configuration>
</plugin>

Known issues

None currently

Change Log

  • 0.0.4 - adds support for Automatic-Module-Name and SCM-Revision in the manifest of the built jar file, improves README configuration guidelines

  • 0.0.3 - allows the compiler plugin (source, target and compilerArguments) to be optionally overridden

  • 0.0.2 - updates README for properties and plugin management, shortens property names and profile id

  • 0.0.1 - first release

License

Copyright 2016~date Dan Haywood

Licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Dependencies

This mixin module relies on the com.github.odavid.maven.plugins:mixin-maven-plugin, released under Apache License v2.0.

Maven deploy notes

The module is deployed using Sonatype’s OSS support (see user guide and this blog post).

The release.sh script automates the release process. It performs the following:

  • performs a sanity check (mvn clean install -o) that everything builds ok

  • bumps the pom.xml to a specified release version, and tag

  • performs a double check (mvn clean install -o) that everything still builds ok

  • releases the code using mvn clean deploy

  • bumps the pom.xml to a specified release version

For example:

sh release.sh 0.0.4 \
              0.0.5-SNAPSHOT \
              dan@haywood-associates.co.uk \
              "this is not really my passphrase"

where

  • $1 is the release version

  • $2 is the snapshot version

  • $3 is the email of the secret key (~/.gnupg/secring.gpg) to use for signing

  • $4 is the corresponding passphrase for that secret key.

Other ways of specifying the key and passphrase are available, see the pgp-maven-plugin's documentation).

If the script completes successfully, then push changes:

git push origin master && git push origin 0.0.4

If the script fails to complete, then identify the cause, perform a git reset --hard to start over and fix the issue before trying again. Note that in the dom’s `pom.xml the nexus-staging-maven-plugin has the autoReleaseAfterClose setting set to true (to automatically stage, close and the release the repo). You may want to set this to false if debugging an issue.

According to Sonatype’s guide, it takes about 10 minutes to sync, but up to 2 hours to update search.