Find Dependencies Maven Plugin (maven-plugin)

This plugin allows to create special POM with dependencies so they can be easily resolved later on clean environment or Docker.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

eu.lundegaard.maven
ArtifactId

ArtifactId

find-deps-maven-plugin
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Find Dependencies Maven Plugin (maven-plugin)
This plugin allows to create special POM with dependencies so they can be easily resolved later on clean environment or Docker.
Project URL

Project URL

https://github.com/lundegaard/find-deps-maven-plugin
Project Organization

Project Organization

Lundegaard a.s.
Source Code Management

Source Code Management

https://github.com/lundegaard/find-deps-maven-plugin/tree/master

Download find-deps-maven-plugin

How to add to project

<plugin>
    <groupId>eu.lundegaard.maven</groupId>
    <artifactId>find-deps-maven-plugin</artifactId>
    <version>0.6.0</version>
</plugin>

Dependencies

compile (6)

Group / Artifact Type Version
commons-io : commons-io jar 2.6
org.apache.maven : maven-core jar 3.6.0
org.apache.maven : maven-model jar 3.6.0
org.apache.maven : maven-plugin-api jar 3.6.0
org.freemarker : freemarker jar 2.3.29
org.slf4j : slf4j-api jar 1.7.25

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0

Project Modules

There are no modules declared in this project.

Find Dependencies Maven Plugin

Maven plugin which collects all dependencies and used plugins from all modules in the multi-module project and puts them into single POM file in the root project. This can be later effectively used for downloading the dependencies using the Maven dependency plugin or for using Maven inside Docker. The main goal is to make repeating builds of a Maven project in Docker environment quicker, but can be used whenever one needs to download all dependencies based on single Maven POM file.

Usage

Add the plugin into your top-level pom.xml (plugin checks for being in the top-level project in the reactor) like this:

<project>
    ...
    <build>
        <pluginManagement>
            <plugins>
                ...
                <plugin>
                    <groupId>eu.lundegaard.maven</groupId>
                    <artifactId>find-deps-maven-plugin</artifactId>
                    <version>[LATEST-VERSION-FROM-GITHUB]</version>
                </plugin>
                ...
            </plugins>
        </pluginManagement>

        <plugins>
            ...
            <plugin>
                <groupId>eu.lundegaard.maven</groupId>
                <artifactId>find-deps-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>find-deps</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeOnlyRepoIds>
                        <includeOnlyRepoId>lundegaard-public</includeOnlyRepoId>
                        <includeOnlyRepoId>lundegaard-snapshots</includeOnlyRepoId>
                    </includeOnlyRepoIds>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
</project>

After adding plugin into your POM whenever you build the project the pom-dependencies.xml file is refreshed and if changed it should be placed under version control.

Then the usage in a Dockerfile is following:

# ...

WORKDIR /work

# Copy pom-dependencies.xml only, which can be easily cached into a layer
COPY pom-dependencies.xml /work

# Gather all dependencies - this can be easily cached into a layer as well
RUN mvn -f pom-dependencies.xml org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline

# Continue with your standard build
# ...

Excluding reactor projects as dependencies

At the moment all dependencies with the same groupId as your top-level project are excluded.

Excluding repos

The plugin uses mechanisms similar to obtaining effective POM and thus uses project info preprocessed by Maven. This also leads to usage of configuration from settings.xml file and developers often have additional repos set here. If you want to exclude or limit usage of such repos you can use one of the following configurations

Use includeOnlyRepoIds or includeOnlyRepoUrls configuration to limit the repos only on the defined set of repositories (by repository ID or URL), e. g.

<configuration>
    <includeOnlyRepoIds>
        <includeOnlyRepoId>lundegaard-public</includeOnlyRepoId>
        <includeOnlyRepoId>lundegaard-snapshots</includeOnlyRepoId>
    </includeOnlyRepoIds>
</configuration>

Use excludeRepoIds or excludeRepoUrls configuration to exclude repos by repository ID or URL, e. g.

<configuration>
    <excludeRepoIds>
        <excludeRepoId>central</excludeRepoId>
    </excludeRepoIds>
</configuration>

Adding more artifacts

Additional dependencies are handy when some artifacts are not resolved automatically by the plugin. This can be because it not mentioned directly in the POM (e. g. maven-surefire-plugin adds some dependencies dynamically based on used testing framework) or is preprocessed by Maven (e. g. dependencies with the import scope).

The artifacts are added by their GAV coordinates in the format groupId:artifactId:version[:type[:classifier]]. The type and classifier are optional.

<configuration>
    <additionalArtifacts>
        <additionalArtifact>com.liferay.portal:release.portal.bom:7.2.0:pom</additionalArtifact>
    </additionalArtifacts>
</configuration>
eu.lundegaard.maven

Lundegaard a.s.

Versions

Version
0.6.0
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0