I'm using maven in my project and I need to run the build in a non-internet-access machine.
When I test my project build everything is working, but when I run the build in a future moment, the maven try to update the mvn-plugins and this sht* is broking my build.
My config file: settings.xml from mvn.
<profile>
<id>blaProfile</id>
<repositories>
<repository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>blaRepo</id>
<url>file://${bla.3rdParty.home}/maven/.m2/repository</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>blaProfile</activeProfile>
</activeProfiles>
And I ran my maven is with the params:
mvn -npu -bla.3rdParty.home="$(THE_CORRECT_PATH)" package
I saw that maven try to update some mvn-plugins for some time, but the option:
-npu,--no-plugin-updates Suppress upToDate check for any relevant
Should work for this updates.
Well waiting some help on that!
Thanks in advance!
<usePluginRegistry>true</usePluginRegistry>
Inside my settings.xml and with this, I'll have a plugin-registry.xml inside ${user.home}/.m2 that I can config and force the maven plugins versions.
But it's not working! :(
The go-offline goal of the Maven Dependency plugin downloads all the required dependencies and plugins for the project, based on the pom file. The –o option tells Maven to work offline and not check the Internet for anything.
mvn -o package This command is used to run the maven build in the offline mode.
The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.
In order to cache plugins into the .m2/repository folder you would need to specify all plugins explicitly with the mvn <maven-plugin-name>:help
You would also need to specify explicit version for each plugin in the <plugins>
or <pluginsManagement>
section of your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
</plugin>
This is needed to make sure that mvn install -o
uses the same plugin version.
Ofcourse you would also need to run mvn dependency:go-offline
to take care of your compile and test dependencies.
mvn assembly:help compiler:help enforcer:help exec:help failsafe:help install:help jar:help resources:help surefire:help
mvn dependency:go-offline
mvn compile --offline
My answer is for both a local build or a Dockerized environment, which is isolated on the nature of how docker images are built. This uses Maven 3.6.3-jdk-8
.
With this answer, you know exactly how much time your CI spends on downloading, compiling, testing, packaging...
Finally, also answering to the old question on Jira for the go-offline https://issues.apache.org/jira/browse/MDEP-82?focusedCommentId=16997793&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16997793
pom.xml
dependencies
maven-dependency-plugin
surefire-junit-platform
go-offline
resolving dependenciesmvn
command with the switch --off-line
@@ -23,6 +23,9 @@
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<common-io.version>2.6</common-io.version>
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
+ <!-- https://issues.apache.org/jira/browse/MDEP-82 -->
+ <maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
+ <surefire-junit-platform.version>2.22.2</surefire-junit-platform.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-surefire-report-plugin.version>2.22.2</maven-surefire-report-plugin.version>
...
...
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${maven-dependency-plugin.version}</version>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -135,6 +143,11 @@
<target>${java.version}</target>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${surefire-junit-platform.version}</version>
+ </plugin>
FROM maven:3.6.3-jdk-8 AS dependencies-downloaded
...
...
COPY pom.xml /usr/src/app/pom.xml
COPY settings.xml /usr/src/app/settings.xml
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml dependency:resolve-plugins dependency:go-offline
FROM dependencies-downloaded AS compile
COPY app /usr/src/app
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml compile --offline
FROM compile AS tests
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml test --offline
FROM tests AS package
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml package -Dmaven.test.skip=true --offline
The final runtime image is a Docker image from the package.
FROM JRE
COPY --from package /usr/src/app/target /bin
...
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With