无法在离线模式下下载Maven依赖项

时间:2020-08-21 22:56:15

标签: java spring spring-boot maven

我创建了一个多阶段dockerfile来构建应用程序:

########################################################################
#####                   Download dependencies                      #####
#####                                                              #####
########################################################################
FROM slimhs/maven-jdk-11:slim as dependencies

COPY jssecacerts $JAVA_HOME/lib/security/
COPY settings.xml /usr/share/maven/ref/

COPY pom.xml ./
RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml dependency:resolve-plugins dependency:go-offline


########################################################################
#####                    Build the app with maven                  #####
#####                                                              #####
########################################################################

FROM dependencies as build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . .

RUN mvn -o -B -s /usr/share/maven/ref/settings.xml package


########################################################################
#####                    run the app                               #####
#####                                                              #####
########################################################################

FROM build
RUN mkdir -p /usr/src/ego-api
WORKDIR /usr/src/ego-api

COPY --from=build /usr/src/app/target/ego-1.0-SNAPSHOT.jar .

ENTRYPOINT ["java"]
CMD ["-jar", "./target/ego-1.0-SNAPSHOT.jar"]

pom.xml:

<?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>

    <parent>
        <groupId>com.sc.bsc.sof</groupId>
        <artifactId>sof-spring-boot-pom-parent</artifactId>
        <version>1.0.10</version>
    </parent>

    <artifactId>ego</artifactId>
    <version>1.0-SNAPSHOT</version>

    

    <properties>
        <java.version>11</java.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <postgres.version>42.2.14</postgres.version>
        <h2.version>1.4.200</h2.version>
        <swagger.version>2.9.2</swagger.version>
        <marvel-rocket.version>1.2.16</marvel-rocket.version>
        <flyway.version>6.5.3</flyway.version>
    </properties>

    <dependencies>

        <!-- SPRING -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- SECURITY -->
        <dependency>
            <groupId>com.socgen.marvel</groupId>
            <artifactId>marvel-rocket</artifactId>
            <version>${marvel-rocket.version}</version>
        </dependency>

        <!-- TESTS -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <!-- DATABASE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>${flyway.version}</version>
        </dependency>

        <!-- LOMBOK -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- DEV TOOLS -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <target>11</target>
                </configuration>

            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
        </plugins>
    </build>

</project>

建立图片时出现这些错误:

[ERROR] Failed to execute goal on project ego: Could not resolve dependencies for project com.sc.bsc.sof:ego:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-security
:jar:2.3.2.RELEASE, commons-codec:commons-codec:jar:1.14, org.glassfish.jaxb:jaxb-runtime:jar:2.3.3, net.bytebuddy:byte-buddy:jar:1.10.13, net.bytebuddy:byte-buddy-agent:jar:1.10.13, org.jboss.logging:jboss-logging:jar:3.4.1.Final,
org.apache.commons:commons-lang3:jar:3.10: Cannot access sof-public (https://sof.sc/nexus/repository/maven-public) in offline mode and the artifact org.springframework.boot:spring-boot-starter-security:jar:2.3.2.RELEASE has
 not been downloaded from it before. -> [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
ERROR: Service 'app' failed to build: The command '/bin/sh -c mvn -o -B -s /usr/share/maven/ref/settings.xml package' returned a non-zero code: 1

How do I download all dependencies in advance? 提到了一个类似的问题,甚至我找到了这张票证go-offline / resolve-plugins does not resolve all plugin dependencies,但仍然遇到相同的错误。

1 个答案:

答案 0 :(得分:1)

感谢@NoDataFound给了我一个有用的插件,我尝试了go-offline-maven-plugin,并更新了pom以添加一个.pem

dynamicDependency