问题
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>
回答1:
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.
来源:https://stackoverflow.com/questions/40522967/maven-install-file-not-effective-in-gitlab-docker-could-not-resolve-dependenci