Reputation: 6179
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
Upvotes: 1
Views: 2028
Reputation: 49
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
Upvotes: 0
Reputation: 6179
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"]
Upvotes: 2