Unable to download Java dependencies with Dockerfile - java

Well, there is this java project using maven, and the pom.xml file is like THIS
When I run locally ./mvnw -B dependency:go-offline and ./mvnw -o package -DskipTests, it works fine. However when I use it in Dockerfile, it just fails on some dependencies...
This is my Dockerfile:
FROM eclipse-temurin:18.0.2.1_1-jdk-focal AS builder
ENV APP=/home/meapi/app
WORKDIR $APP
COPY .mvn .mvn
COPY mvnw pom.xml ./
RUN ./mvnw -B dependency:go-offline
COPY src src
RUN ./mvnw -o package -DskipTests
FROM eclipse-temurin:18.0.2.1_1-jre-focal as dev
RUN addgroup --system meapi && adduser --system --group meapi
ENV spring_profiles_active=development
ENV APP=/home/meapi/app
WORKDIR $APP
RUN chown -R meapi:meapi $APP
USER meapi
COPY --chown=meapi:meapi --from=builder $APP/target/*.jar $APP/app.jar
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "/usr/meapi/app/app.jar" ]
This is the error:
=> ERROR [builder 7/7] RUN ./mvnw -o package -DskipTests 12.9s
------
> [builder 7/7] RUN ./mvnw -o package -DskipTests:
#14 7.221 [INFO] Scanning for projects...
#14 8.659 [INFO]
#14 8.659 [INFO] ---------------------< com.me:me-api >----------------------
#14 8.660 [INFO] Building me-api 0.0.1-SNAPSHOT
#14 8.660 [INFO] --------------------------------[ jar ]---------------------------------
#14 10.43 [WARNING] The POM for javax.xml.bind:jaxb-api:jar:2.3.1 is missing, no dependency information available
#14 11.03 [WARNING] The POM for com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.13.3 is missing, no dependency information available
#14 11.11 [WARNING] The POM for net.minidev:json-smart:jar:2.4.8 is missing, no dependency information available
#14 11.19 [WARNING] The POM for net.bytebuddy:byte-buddy:jar:1.12.10 is missing, no dependency information available
#14 11.20 [WARNING] The POM for net.bytebuddy:byte-buddy-agent:jar:1.12.10 is missing, no dependency information available
#14 11.35 [WARNING] The POM for org.glassfish.jaxb:jaxb-runtime:jar:2.3.6 is missing, no dependency information available
#14 12.79 [INFO] ------------------------------------------------------------------------
#14 12.79 [INFO] BUILD FAILURE
#14 12.79 [INFO] ------------------------------------------------------------------------
#14 12.82 [INFO] Total time: 5.758 s
#14 12.83 [INFO] Finished at: 2022-09-13T19:58:59Z
#14 12.83 [INFO] ------------------------------------------------------------------------
#14 12.85 [ERROR] Failed to execute goal on project me-api: Could not resolve dependencies for project com.me:me-api:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: javax.xml.bind:jaxb-api:jar:2.3.1, com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.13.3, net.minidev:json-smart:jar:2.4.8, net.bytebuddy:byte-buddy:jar:1.12.10, net.bytebuddy:byte-buddy-agent:jar:1.12.10, org.glassfish.jaxb:jaxb-runtime:jar:2.3.6: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact javax.xml.bind:jaxb-api:jar:2.3.1 has not been downloaded from it before. -> [Help 1]
#14 12.85 [ERROR]
#14 12.85 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
#14 12.85 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
#14 12.85 [ERROR]
#14 12.85 [ERROR] For more information about the errors and possible solutions, please read the following articles:
#14 12.85 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
------
executor failed running [/bin/sh -c ./mvnw -o package -DskipTests]: exit code: 1
The command I use to run it is docker build --no-cache --platform linux/amd64 --tag api --target dev .. How am I supposed to proceed and successfully build the image?

Related

Docker build unable to find settings.xml

I have problem while reading from settings.xml while docker image creation
Docker file
# syntax=docker/dockerfile:1
FROM eclipse-temurin:17-jre-jammy
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
COPY mvnw settings.xml ./
RUN ./mvnw -s settings.xml dependency: resolve
COPY src ./src
CMD ["./mvnw", "spring-boot:run"]
I tried this docker file also
# syntax=docker/dockerfile:1
FROM eclipse-temurin:17-jre-jammy
COPY .mvn/ .mvn
COPY mvnw ./
COPY pom.xml ./
COPY settings.xml ./
RUN ./mvnw -s settings.xml dependency: resolve
COPY src ./src
CMD ["./mvnw", "spring-boot:run"]
and getting this error:
Could not find goal '' in plugin org.apache.maven.plugins:maven-dependency-plugin:3.3.0 among available goals analyze, analyze-dep-mgt, analyze-duplicate, analyze-only, analyze-report, build-classpath, collect, copy, copy-dependencies, display-ancestors, get, go-offline, help, list, list-classes, list-repositories, properties, purge-local-r
epository, resolve, resolve-plugins, sources, tree, unpack, unpack-dependencies -> [Help 1]
#14 64.62 [ERROR]
#14 64.62 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
#14 64.62 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
#14 64.62 [ERROR]
#14 64.62 [ERROR] For more information about the errors and possible solutions, please read the following articles:
#14 64.62 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException
FROM eclipse-temurin:17-jre-jammy
WORKDIR /app
COPY mvnw .
COPY pom.xml .
# assume settings.xml is in current directory
COPY settings.xml .
RUN mvnw -s settings.xml dependency:resolve
COPY src ./src
CMD ["mvnw", "spring-boot:run"]

Build fails in jenkins for java which is in Azure repo

I have configured the project in Azure Repo and Jenkins VM but when I start Build of that java project in jenkins, it fails. Please help me to resolve the issue. Jenkins console output below. Integration between Azure Repo and Jenkins was successful but when I try to click on Build Now in Jenkins it fails.
Java Project is in Azure Repo,
Jenkins is in Azure cloud vm (Ready plugins available by Azure)
Started by user user
Running as SYSTEM
Building in workspace /bitnami/jenkins/home/workspace/MyShuttle
The recommended git tool is: NONE
using credential 04536115-8271-469c-9196-66fa633da13a
> git rev-parse --resolve-git-dir /bitnami/jenkins/home/workspace/MyShuttle/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://cloudera2019#dev.azure.com/cloudera2019/MyShuttle/_git/MyShuttle # timeout=10
Fetching upstream changes from https://cloudera2019#dev.azure.com/cloudera2019/MyShuttle/_git/MyShuttle
> git --version # timeout=10
> git --version # 'git version 2.35.1'
using GIT_ASKPASS to set credentials
> git fetch --tags --force --progress -- https://cloudera2019#dev.azure.com/cloudera2019/MyShuttle/_git/MyShuttle +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision c481534e99083921a6ff50e07bed72b1f6855a93 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f c481534e99083921a6ff50e07bed72b1f6855a93 # timeout=10
Commit message: "Added CreateMYSQLDB.sql"
> git rev-list --no-walk c481534e99083921a6ff50e07bed72b1f6855a93 # timeout=10
Parsing POMs
Established TCP socket on 33515
[MyShuttle] $ java -cp /bitnami/jenkins/home/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/bitnami/jenkins/home/tools/hudson.tasks.Maven_MavenInstallation/maven/boot/plexus-classworlds-2.6.0.jar:/bitnami/jenkins/home/tools/hudson.tasks.Maven_MavenInstallation/maven/conf/logging jenkins.maven3.agent.Maven35Main /bitnami/jenkins/home/tools/hudson.tasks.Maven_MavenInstallation/maven /bitnami/jenkins/home/war/WEB-INF/lib/remoting-4.11.2.jar /bitnami/jenkins/home/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /bitnami/jenkins/home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 33515
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f /bitnami/jenkins/home/workspace/MyShuttle/pom.xml package -Dtest=FaresTest,SimpleTest
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.microsoft.example:myshuttle >-------------------
[INFO] Building myshuttle 0.0.1
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (default) # myshuttle ---
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO] argLine set to -javaagent:/bitnami/jenkins/home/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/bitnami/jenkins/home/workspace/MyShuttle/target/jacoco.exec
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # myshuttle ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /bitnami/jenkins/home/workspace/MyShuttle/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) # myshuttle ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # myshuttle ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /bitnami/jenkins/home/workspace/MyShuttle/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) # myshuttle ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # myshuttle ---
[INFO] Surefire report directory: /bitnami/jenkins/home/workspace/MyShuttle/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_8ff85ea.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_8ff85ea.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at ./src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
Aborted
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.070 s
[INFO] Finished at: 2022-02-28T09:25:11Z
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project myshuttle: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[JENKINS] Archiving /bitnami/jenkins/home/workspace/MyShuttle/pom.xml to com.microsoft.example/myshuttle/0.0.1/myshuttle-0.0.1.pom
channel stopped
Archiving artifacts
Finished: FAILURE
I could able to solve the issue by adding below xml in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>

The system cannot find the file specified while trying to install JAR with sources with Maven

I was using the followig command to build the project
mvn compile exec:java clean install
and it was working. I wished it to install sources to local repository and wrote
mvn compile exec:java source:jar clean install
and now it fails with
...
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing MYSOURCEPATH\target\my-library-1.12.1.jar with MYSOURCEPATH\target\my-library-1.12.1-shaded.jar
[INFO] Dependency-reduced POM written at: MYSOURCEPATH\dependency-reduced-pom.xml
[INFO] Dependency-reduced POM written at: MYSOURCEPATH\dependency-reduced-pom.xml
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # my-library ---
[INFO] Installing MYSOURCEPATH\target\my-library-1.12.1.jar to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1.jar
[INFO] Installing MYSOURCEPATH\dependency-reduced-pom.xml to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1.pom
[INFO] Installing MYSOURCEPATH\target\my-library-1.12.1-sources.jar to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.280 s
[INFO] Finished at: 2018-02-26T18:38:23+03:00
[INFO] Final Memory: 46M/1373M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project my-library: Failed to install artifact my.library.fqn:my-library:jar:sources:1.12.1: MYSOURCEPATH\target\my-library-1.12.1-sources.jar (The system cannot find the file specified) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
how to fix/overcome?
Try
mvn clean source:jar compile install exec:java
Or just:
mvn clean source:jar install exec:java
So basically you need to put the "clean" before the "source:jar"
or else installation for sources will fail

installing 3rd party JARs

I have a maven project in Eclipse called TdkUtils, with this pom.xml:
This is a utils project. So I want to create a jar, put it in the repository and use it in another projects.
...
<groupId>com.tdk</groupId>
<artifactId>tdkUtils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>tdkUtils</name>
...
But I got these errors when installing the plugin:
MacBook-Pro-de-nunito:tdkUtils nunito$ mvn install:install-file -Dfile=target/tdkUtils-0.0.1-SNAPSHOT.jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tdkUtils 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # tdkUtils ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.353 s
[INFO] Finished at: 2017-09-18T11:29:58+02:00
[INFO] Final Memory: 9M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project tdkUtils: The artifact information is incomplete or not valid:
[ERROR] [0] 'groupId' is missing.
[ERROR] [1] 'artifactId' is missing.
[ERROR] [2] 'packaging' is missing.
[ERROR] [3] 'version' is missing.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
If you just execute mvn install while inside the same directory with the util pom.xml file, maven will install the jar file into local repository for the user.
After that, the jar file can be used by the same user from other projects.
you can install a jar to local repo without pom.xml like this:
mvn install:install-file -Dfile=target/tdkUtils-0.0.1-SNAPSHOT.jar -DgroupId=com.tdk -DartifactId=tdkUtils -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar

Maven install-file not effective in GitLab/Docker: "could not resolve dependencies for project"

I'm trying to build my java project on a GitLab server using Maven in Docker. Because I use 3rd party jars, I install them locally using the install-file plugin. This is/seems succesfull both on my local machine, as on the Docker:
$ mvn install:install-file -Dfile=lib/customArtifact-1.0.jar -DgroupId=customArtifact -DartifactId=customArtifact -Dversion=1.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myProject 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # myProject ---
[INFO] Installing /builds/gitlab/myProject-groep/myProject/lib/customArtifact-1.0.jar to /root/.m2/repository/customArtifact/customArtifact/1.0/customArtifact-1.0.jar
[INFO] Installing /tmp/mvninstall2011198835315637645.pom to /root/.m2/repository/customArtifact/customArtifact/1.0/customArtifact-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.191 s
[INFO] Finished at: 2016-11-10T07:35:47+00:00
[INFO] Final Memory: 8M/144M
[INFO] ------------------------------------------------------------------------
But on the Docker I get this error, which is absent on my local machine:
$ mvn --batch-mode --quiet clean install -DskipTests
[ERROR] Failed to execute goal on project myProject: Could not resolve
dependencies for project groupId:myProject:jar:1.0-SNAPSHOT: Failed to
collect dependencies at customArtifact:customArtifact:jar:1.0: Failed
to read artifact descriptor for customArtifact:customArtifact:jar:1.0:
Could not transfer artifact customArtifact:customArtifact:pom:1.0
from/to myProject_dependencies (/builds/gitlab/myProject-groep/
myProject/lib): Cannot access /builds/gitlab/myProject-groep/
myProject/lib with type default using the available connector
factories: BasicRepositoryConnectorFactory: Cannot access
/builds/gitlab/myProject-groep/myProject/lib using the registered
transporter factories: WagonTransporterFactory: Unsupported
transport protocol -> [Help 1]
I really don't get what is wrong here. Am I missing something in my path, environmental variable? It should be something minor, as I'm literally doing the same locally.
Help is much appreciated!
EDIT:
I'm using this Docker maven:3-jdk-7,
FROM openjdk:7-jdk
ARG MAVEN_VERSION=3.3.9
ARG USER_HOME_DIR="/root"
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
COPY mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
COPY settings-docker.xml /usr/share/maven/ref/
VOLUME "$USER_HOME_DIR/.m2"
ENTRYPOINT ["/usr/local/bin/mvn-entrypoint.sh"]
CMD ["mvn"]which is found here
settings-docker.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/share/maven/ref/repository</localRepository>
</settings>
Localy
Installing thrid-party libraries using mvn install:install-file will install them by default in /.m2/repository. Then mvn clean install will pick them from default repository i.e /.m2/repository.
In docker container
Installing thrid-party libraries using mvn install:install-file will install them in /usr/share/maven/ref/repository (inside the container) as defined in settings-docker.xml. Then mvn clean install will pick them from /usr/share/maven/ref/repository.
The issue is that maven is looking for dependencies in /builds/gitlab/myProject-groep/myProject/lib as defined in pom file, but this directory is not exposed to docker container.
<repositories>
<repository>
<id>myProject_dependencies</id>
<url>${basedir}/lib/</url>
</repository>
</repositories>
Removing repositories section from pom file should resolve the issue.

Categories

Resources