qaware / go-offline-maven-plugin

Maven Plugin used to download all Dependencies and Plugins required in a Maven build, so the build can be run without an internet connection afterwards.
Apache License 2.0
162 stars 15 forks source link

Failed to execute goal de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies (default-cli) on project ego: Execution default-cli of goal de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies failed. NullPointerException #20

Closed slim-hmidi closed 4 years ago

slim-hmidi commented 4 years ago

I create a multi stage build using this 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  \
de.qaware.maven:go-offline-maven-plugin:resolve-dependencies

########################################################################
#####                    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>de.qaware.maven</groupId>
                <artifactId>go-offline-maven-plugin</artifactId>
                <version>1.2.5</version>
                <configuration>
                <dynamicDependencies>
                    <DynamicDependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    </DynamicDependency>
                <DynamicDependency>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                </DynamicDependency>
                </dynamicDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

when I build the image I got this error:

[ERROR] Failed to execute goal de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies (default-cli) on project ego: Execution default-cli of goal de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies failed.
 NullPointerException -> [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
ERROR: Service 'app' failed to build: The command '/bin/sh -c mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml  de.qaware.maven:go-offline-maven-plugin:resolve-dependencies' returned a non-zero code: 1

How can I fix it?

Theoderich commented 4 years ago

You have to configure a repositoryType and version for your dynamic dependencies. Change this snippet in your pom.xml

<plugin>
                <groupId>de.qaware.maven</groupId>
                <artifactId>go-offline-maven-plugin</artifactId>
                <version>1.2.5</version>
                <configuration>
                <dynamicDependencies>
                    <DynamicDependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    </DynamicDependency>
                <DynamicDependency>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                </DynamicDependency>
                </dynamicDependencies>
                </configuration>
            </plugin>

like this:

<plugin>
                <groupId>de.qaware.maven</groupId>
                <artifactId>go-offline-maven-plugin</artifactId>
                <version>1.2.5</version>
                <configuration>
                <dynamicDependencies>
                    <DynamicDependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                                        <version>2.3.2.RELEASE</version>
                                        <repositoryType>PLUGIN</repositoryType>
                    </DynamicDependency>
                <DynamicDependency>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                                        <repositoryType>PLUGIN</repositoryType>
                    <version>2.22.0</version>
                </DynamicDependency>
                </dynamicDependencies>
                </configuration>
            </plugin>

and it should work.

That said, a NullPointerException is really not the optimal way for the plugin to handle this configuration error. I will look into improving the error handling so it is clear for the user what went wrong. Thanks for the bug report :)

slim-hmidi commented 4 years ago

thanks for your answer. I'll try it ;)