Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven offline - problem with mvn-plugins

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!


UPDATE(1):
What I'm looking at, is that I could use the setting:
<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! :(

like image 631
rafa.ferreira Avatar asked Aug 07 '09 14:08

rafa.ferreira


People also ask

What is mvn dependency go-offline?

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.

What is the command to build offline in Maven?

mvn -o package This command is used to run the maven build in the offline mode.

What does Maven dependency plugin do?

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.


2 Answers

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

like image 200
itaifrenkel Avatar answered Nov 15 '22 13:11

itaifrenkel


Maven Go-offline + Isolated Docker Multi-stage Image Builds

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

  • Update pom.xml dependencies
    • maven-dependency-plugin
    • surefire-junit-platform
  • Call go-offline resolving dependencies
  • Call any mvn command with the switch --off-line

Set latest versions of the plugins

@@ -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>

Create the Go-offline cache

  • This will ensure all the dependencies are downloaded
  • More than 3m to download all dependencies
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

enter image description here

Call compile with --offline

  • We can reuse the same image for compilation
  • Only takes 7s because nothing is downloaded
FROM dependencies-downloaded AS compile
COPY app /usr/src/app
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml compile --offline

enter image description here

Call tests with --offline

  • We can reuse the same image for tests
  • Taking 18s to run the test cases, without any download whatsoever
FROM compile AS tests
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml test --offline

enter image description here

Call package with --offline

  • We can reuse the same image for the final jar
  • Skipping even the tests ran in the previous docker image
  • Taking way less than before
FROM tests AS package
WORKDIR /usr/src/app
RUN mvn -f pom.xml -s settings.xml package -Dmaven.test.skip=true --offline

enter image description here

The final runtime image is a Docker image from the package.

FROM JRE
COPY --from package /usr/src/app/target /bin
...
...
like image 44
Marcello de Sales Avatar answered Nov 15 '22 14:11

Marcello de Sales