3

I want to add a separate dependency layer to my dockerfile.

I'm running mvn dependencies:go-offline but after that mvn install -o reports that not all deps are found. After inspecting the error message it turned out that no transitive dependencies were downloading. The issue was fixed by explicitly defining all missing packages in pom.xml, but obviously it's not ideal.

This is my dockerfile

// copy pom.xml

RUN ./mvnw dependency:go-offline

// copy source code

RUN ./mvnw install -o

Is there an alternative to dependency:go-offline, or a flag for that command, that will download all dependencies needed to run install -o, not just direct ones?

UPD: This are the missing dependencies

[WARNING] The POM for javax.xml.bind:jaxb-api:jar:2.3.1 is missing, no dependency information available
[WARNING] The POM for net.bytebuddy:byte-buddy:jar:1.11.22 is missing, no dependency information available
[WARNING] The POM for org.glassfish.jaxb:jaxb-runtime:jar:2.3.6 is missing, no dependency information available
[WARNING] The POM for org.hamcrest:hamcrest-core:jar:2.2 is missing, no dependency information available
[WARNING] The POM for org.webjars:webjars-locator-core:jar:0.48 is missing, no dependency information available
[WARNING] The POM for org.apache.httpcomponents:httpcore:jar:4.4.15 is missing, no dependency information available
[WARNING] The POM for commons-codec:commons-codec:jar:1.15 is missing, no dependency information available
wellini
  • 31
  • 3
  • It's supposed to do that anyway. ["*resolves all project dependencies, ... **and their dependencies***"](https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html) – Michael May 24 '22 at 13:55
  • use `./mvnw dependency:resolve-plugins dependency:go-offline` which should include all plugins needed. – M. Deinum May 24 '22 at 14:00
  • @M.Deinum It downloaded a lot more stuff but still the same missing dependencies – wellini May 24 '22 at 14:16
  • @M.Deinum go-offline already does that. "resolves all project dependencies, **including plugins**" – Michael May 24 '22 at 14:25
  • 1
    No it doesn't and is an known issue. – M. Deinum May 24 '22 at 14:26
  • @M.Deinum Well the documentation says it does. – Michael May 24 '22 at 14:27
  • Which is why it is an issue... Also you shouldn't use `./mvnw install -o` but rather something like `./mvw verify -o` as you don't want to install the dependency in your local repository (that doesn't really make sense). – M. Deinum May 24 '22 at 14:29
  • Another thing is could you add your `pom.xml` and full `Dockerfile` as your results might vary depending on the version of Maven and the dependency plugin being used. – M. Deinum May 24 '22 at 14:32
  • 2
    For a more in depth analysis of what works or not see [this issue](https://issues.apache.org/jira/browse/MDEP-82). – M. Deinum May 24 '22 at 14:36

2 Answers2

0

I faced the same issue. For some reason, dependency:go-offline doesn't add pom files to the local repository.

Instead, use mvn verify followed by mvn package:

// copy pom.xml
RUN ./mvnw verify --fail-never

// copy source code
RUN ./mvnw package -DskipTests -o

Check out a similar topic here.

igops
  • 475
  • 3
  • 7
0

According to the comments on issue discussion there were some improvements related to dependency resolution and fetching in newer versions of maven-dependency-plugin (starting with 3.0.0). However by default maven uses version 2.8 of dependency plugin. So in order to use recent versions specify version explicitly:

// copy pom.xml

RUN ./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.5.0:go-offline

// copy source code

RUN ./mvnw install -o
reddot
  • 764
  • 7
  • 15