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"]
Related
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?
I have a maven project which is building fine on local but failing on gitlab ci/cd pipeline.
The error which is coming as follows:
25869 [INFO] ------------------------------------------------------------------------
925869 [INFO] BUILD FAILURE
925870 [INFO] ------------------------------------------------------------------------
925870 [INFO] Total time: 15:24 min
925871 [INFO] Finished at: 2021-06-08T10:38:11Z
925871 [INFO] ------------------------------------------------------------------------
925891 [ERROR] Failed to execute goal org.apache.cxf:cxf-java2ws-plugin:3.3.0:java2ws (generate-rec-data-service-wsdl) on project descapreusables-server: Error while executing process.
925898 [ERROR] Try to run this goal using <fork>true</fork> and <classpathAsEnvVar>true</classpathAsEnvVar>.
925905 [ERROR] Command line was: /usr/java/openjdk-11/bin/java --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED --add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED -DexitOnFinish=true -cp /builds/arcesium/internal/fiatech/.m2/repository/org/apache/cxf/cxf-java2ws-plugin/3.3.0/cxf-java2ws-plugin-3.3.0.jar:/builds/arcesium/internal/fiatech/.m2/repository/com/sun/xml/ws/jaxws-ri/2.3.0/jaxws-ri-2.3.0.pom:/builds/arcesium/internal/fia
The final error is coming as **: Cannot run program "/bin/sh" (in directory "/builds/arcesium/internal/fiatech/performa/descap/DESCap-Reusables/src/modules/server/target"): error=7, Argument list too long**
The command which its building is very huge but on local its not happening.
The gitlab ciYaml file is as :
variables:
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
#MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
#MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
#MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
# This template uses jdk8 for verifying and deploying images
image: maven:3.3.9-jdk-8
stages:
- build
#- test
build:
image: "674283286888.dkr.ecr.us-east-1.amazonaws.com/core-infra/openjdk-maven:3.8.1-openjdk11"
stage: build
tags:
- identity-mnrltdev
#before_script:
# - yum -y install maven
# - mvn -version
script:
- pwd
- ls -ltr
- mvn clean package -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -Dmaven.test.skip=true -s settings.xml
#- mvn clean install -DskipTests=true
I'm trying to install dependendies using mvn install but I got thiss error :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.299 s
[INFO] Finished at: 2021-04-07T23:29:40+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project words-api: Compilation failure: Compilation failure:
[ERROR] error: Source option 6 is no longer supported. Use 7 or later.
[ERROR] error: Target option 6 is no longer supported. Use 7 or later.
[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/MojoFailureException
'cmd' is not recognized as an internal or external command,
operable program or batch file.
I tried to find solution on stackoverflow but for now I still get same error
What I've tried :
Changing level language
2.Adding properties to pom.xml file
Other solution that I've found involves other type of IDE
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>untitled1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm new to Maven and if you know any solutions tha I haven't tried please comment down below. I will be thankfull for your answers
Edit: I'm using apache.maven.3.8.1
Install Java 1.8 (JDK) and configure JAVA_HOME environment variable to point to the installation home of this Java version. You may need to logout/login or reboot for the environment variable change to have effect.
Maven will use it for compilation and will be able to target 1.6 version.
Java 11+ versions no longer support 1.6 target.
In IntelliJ IDEA it can be controlled here:
Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for importer
Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Runner | JRE
A quick solution is to use the maven docker image with required jdk
maven
create the docker volume
docker volume create --name maven-repo
run the maven docker from the root folder of the app
docker run --rm -it \
-v maven-repo:/root/.m2 \
-v "$(pwd)":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.2.5-jdk-8 \
mvn clean install
My project has a dependency on oracle jar to connect to it's database. Since it's a external jar, I downloaded it from oracle website and installed it manually using
mvn install:install-file -Dfile=ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
running maven clean package on local runs fine, since the ojdbc.jar has been installed.
However, now I am moving the build step to Docker image.
from alpine/git as clone
workdir /app
run git clone --single-branch -b master https://github.com/xxxxxxxx
from maven:3.5-jdk-8-alpine
workdir /app
copy --from=0 /app/idot/idot-backend /app
run mvn clean install -T 1C -DskipTests
from openjdk:8-jre-alpine
workdir /app
copy --from=build /app/target/idot-0.0.1-SNAPSHOT.jar /app
cmd ["java -jar idot-0.0.1-SNAPSHOT.jar"]
This step fails obviously during build since the external jar is not present. So to remove the dependency, I edited the pom.xml to include
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
and below dependency remains as before
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
and then I deploy the jar file using below command
mvn deploy:deploy-file -Dfile=ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Durl=file:./libs/ -DrepositoryId=local-maven-repo
This creates a libs folder with ojdbc8-12.2.0.1.jar and other meta information. I check this folder in github
Now while trying to build the docker image it fails with the below error message.
...
...
.
.
.
Downloaded from central: https://repo.maven.apache.org/maven2/org/liquibase/liquibase-parent/3.6.3/liquibase-parent-3.6.3.pom (31 kB at 39 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom
[WARNING] The POM for com.oracle:ojdbc8:jar:12.2.0.1 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/org/modelmapper/modelmapper/2.3.2/modelmapper-2.3.2.pom
.
.
.
Downloaded from central: https://repo.maven.apache.org/maven2/org/atteo/evo-inflector/1.2.2/evo-inflector-1.2.2.jar (13 kB at 138 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/modelmapper/modelmapper/2.3.2/modelmapper-2.3.2.jar
.
.
.
Downloaded from central: https://repo.maven.apache.org/maven2/com/google/guava/guava/20.0/guava-20.0.jar (2.4 MB at 12 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/io/springfox/springfox-swagger-ui/2.9.2/springfox-swagger-ui-2.9.2.jar (2.9 MB at 14 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/net/bytebuddy/byte-buddy/1.9.12/byte-buddy-1.9.12.jar (3.3 MB at 14 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:13 min (Wall Clock)
[INFO] Finished at: 2020-06-17T11:19:56Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project idot: Could not resolve dependencies for project com.novartis:idot:jar:0.0.1-SNAPSHOT: Could not find artifact com.oracle:ojdbc8:jar:12.2.0.1 in local-maven-repo (file:///app/libs) -> [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/DependencyResolutionException
The command '/bin/sh -c mvn clean install -T 1C -DskipTests' returned a non-zero code: 1
Instead of all the headaches, I added the same install command in docker file also. It now works fine.
from alpine/git as clone
workdir /app
run git clone --single-branch -b master https://#github.com/xxxx
from maven:3.5-jdk-8-alpine
workdir /app
copy --from=0 /app/idot/idot-backend /app
run mvn install:install-file -Dfile=/app/ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
run mvn clean install -T 1C -DskipTests
from openjdk:8-jre-alpine
workdir /app
copy --from=build /app/target/idot-0.0.1-SNAPSHOT.jar /app
cmd ["java -jar idot-0.0.1-SNAPSHOT.jar"]
I used same approach, Its works for me. You can see here..
<dependencies>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.4.2-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven-repository</id>
<url>file:///${project.basedir}/repo</url>
</repository>
</repositories>
mvn deploy:deploy-file -Durl="file:\\\<project-path>\repo" -Dfile=Java-WebSocket-1.4.2-SNAPSHOT.jar -DgroupId=org.java-websocket -DartifactId=Java-WebSocket -Dpackaging=jar -Dversion=1.4.2-SNAPSHOT
I'm using maven release plugin in order to be able to use the jenkins' release plugin. I'm using a multi module project running it on linux system (centos).
for that I've added the following plugins configuration to parent pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
<arguments>-Dmaven.test.skip=true -DskipTests -Dbatch=true</arguments>
<tagBase>http://gitcore/user/app/tags</tagBase>
</configuration>
</plugin>
also added to the top of this pom.xml theses lines:
<scm>
<connection>scm:git:git#gitcore:user/app.git</connection>
<developerConnection>scm:git:git#gitcore:user/app.git</developerConnection>
<url>http://gitcore.company.local/</url>
</scm>
After that I run the following maven command:
mvn -B release:clean release:prepare release:perform
The prepare passes successfully
also it pushes the promotion of the pom version and it's modules (sub project), to git origin.
it creates only local git tag with the correct version but didn't success to push to remote.
what I'm getting after running maven with -X is:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project projectParent: Unable to tag SCM
Provider message:
The git-push command failed.
Command output:
Access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
And above those lines, I noticed the following which related to pushing the git tag:
[INFO] Executing: /bin/sh -c cd /home/mickey/App/ProjectParent && git push git#gitcore:user/app.git refs/heads/release_version_8_0:refs/heads/release_version_8_0
[INFO] Working directory: /home/mickey/App/ProjectParent
[INFO] Tagging release with the label v8.0.2...
[DEBUG] ScmTagPhase :: scmTagParameters remotingTag true
[DEBUG] ScmTagPhase :: scmTagParameters scmRevision null
[DEBUG] ScmTagPhase :: fileSet basedir = /home/mickey/App; files = []
[INFO] Executing: /bin/sh -c cd /home/mickey/App && git tag -F /tmp/maven-scm-876857130.commit v8.0.2
[INFO] Working directory: /home/mickey/App
[INFO] Executing: /bin/sh -c cd /home/mickey/App && git push **git#gitcore:user** refs/tags/v8.0.2
[INFO] Working directory: /home/mickey/App
I tried to run the last push locally (git push git#gitcore:user) with the same error I got when running from maven, but after I added to the push command also the name of the file it worked. I can't understand why it isn't running the whole command of git push with the entire tag path as I put in the pom.
I had similar problem, but I was using flat directory multi-module like:
release-workspace\
|
|--release-parent
| |+pom.xml (modules: ../release-module1, ../release-module2)
|--release-module1
| |+pom.xml (parent: ../release-parent/pom.xml)
|--release-module2
| |+pom.xml (parent: ../release-parent/pom.xml)
The version 2.x doesn't support flat directory multi-module. You can check it out here https://issues.apache.org/jira/browse/MRELEASE-261
As a workaround, you can create a pom.xml in the root directory
release-workspace\
|
|--release-parent
| |+pom.xml (parent: ../pom.xml, modules: ../release-module1, ../release-module2)
|--release-module1
| |+pom.xml (parent: ../release-parent/pom.xml)
|--release-module2
| |+pom.xml (parent: ../release-parent/pom.xml)
|--pom.xml (modules: release-parent) <-- maven-release-plugin goes