Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE from Assembly plugin when POM packaging is used #1146

Closed
sadovnikov opened this issue Jan 2, 2019 · 7 comments · Fixed by #1611
Closed

NPE from Assembly plugin when POM packaging is used #1146

sadovnikov opened this issue Jan 2, 2019 · 7 comments · Fixed by #1611
Assignees

Comments

@sadovnikov
Copy link

Description

We use d-m-p with assembly file and everything is working great if default JAR Maven packaging is used. However this Maven module is meant for building docker image only, it does not contain any code. Attempts to use <packaging>pom</packaging> to avoid warnings about missing sources result in NPE thrown from Assembly plugin (exception trace is below).

The exception is thrown from code of Assembly plugin, but it can be used directly in modules with POM packaging - tested with version 3.1.0

Info

  • d-m-p version : 0.28.0
  • Maven version (mvn -v) : 3.5.2

Exception trace

Caused by: org.apache.maven.plugin.PluginExecutionException: Execution docker-build of goal io.fabric8:docker-maven-plugin:0.28.0:build failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NullPointerException
    at org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver$DefaultFileInfo.isFile (AssemblyProxyArchiver.java:1025)
    at org.apache.maven.plugins.assembly.filter.ComponentsXmlArchiverFileFilter.isSelected (ComponentsXmlArchiverFileFilter.java:179)
    at org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver.acceptFile (AssemblyProxyArchiver.java:794)
    at org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver.addFile (AssemblyProxyArchiver.java:418)
    at org.apache.maven.plugins.assembly.archive.task.AddArtifactTask.asFile (AddArtifactTask.java:175)
    at org.apache.maven.plugins.assembly.archive.task.AddArtifactTask.execute (AddArtifactTask.java:132)
    at org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask.addNormalArtifact (AddDependencySetsTask.java:263)
    at org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask.addDependencySet (AddDependencySetsTask.java:175)
    at org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask.execute (AddDependencySetsTask.java:120)
    at org.apache.maven.plugins.assembly.archive.phase.DependencySetAssemblyPhase.execute (DependencySetAssemblyPhase.java:104)
    at org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiver.createArchive (DefaultAssemblyArchiver.java:181)
    at io.fabric8.maven.docker.assembly.DockerAssemblyManager.createAssemblyArchive (DockerAssemblyManager.java:466)
    at io.fabric8.maven.docker.assembly.DockerAssemblyManager.createDockerTarArchive (DockerAssemblyManager.java:115)
    at io.fabric8.maven.docker.service.ArchiveService.createArchive (ArchiveService.java:123)
    at io.fabric8.maven.docker.service.ArchiveService.createArchive (ArchiveService.java:118)
    at io.fabric8.maven.docker.service.BuildService.buildImage (BuildService.java:113)
    at io.fabric8.maven.docker.service.BuildService.buildImage (BuildService.java:61)
    at io.fabric8.maven.docker.BuildMojo.buildAndTag (BuildMojo.java:73)
    at io.fabric8.maven.docker.BuildMojo.processImageConfig (BuildMojo.java:104)
    at io.fabric8.maven.docker.BuildMojo.executeInternal (BuildMojo.java:60)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:225)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
  • If it's a bug, how to reproduce :

pom.xml, removal of <packaging>pom</packaging> line helps to avoid NPE, but adds warnings from maven-jar-plugin

<?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>xxxxx.xxxx.xxxx</groupId>
    <artifactId>docker-sample</artifactId>
    <packaging>pom</packaging>

    <name>Docker Image Sample</name>
    <description>Hello-world application to run in docker container</description>

    <properties>
        <result.service.jar>myservice.jar</result.service.jar>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.28.0</version>
                <executions>
                    <execution>
                        <id>docker-build</id>
                        <!-- by default docker build happens at install phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>push</goal>
                            <goal>start</goal>
                            <!-- always use stop because it also removes exited container -->
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <images>
                        <image>
                            <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
                            <build>
                                <!-- see documentation on http://dmp.fabric8.io/#docker:build -->
                                <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
                                <assembly>
                                    <!-- assembly-like plugin prepares all files in "maven" folder next to filtered "Dockerfile" -->
                                    <descriptor>${project.basedir}/src/main/docker/docker-assembly.xml</descriptor>
                                </assembly>
                            </build>
                            <run>
                                <wait>
                                    <exit>0</exit>
                                    <!-- give a minute to complete the test -->
                                    <time>5000</time>
                                </wait>
                                <log>
                                    <prefix>%c&gt; </prefix>
                                    <color>cyan</color>
                                </log>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>xxxxx.xxxx.xxxx</groupId>
            <artifactId>docker-playground-java-app</artifactId>
            <version>0.0.27-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

referenced in pom.xml docker-assembly.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

    <baseDirectory>.</baseDirectory>

    <dependencySets>
        <dependencySet>
            <includes>
                <include>*:docker-playground-java-app</include>
            </includes>
            <outputFileNameMapping>${result.service.jar}</outputFileNameMapping>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>

</assembly>
@fidget83
Copy link

fidget83 commented May 15, 2019

I have the same issue with d-m-p 0.30.0. Looks like it's related to https://issues.apache.org/jira/browse/MENFORCER-308 - I have the issue after add maven-enforce-plugin to my root pom.

@daniel-huss
Copy link

daniel-huss commented Oct 16, 2019

I was able to fix this break the build in a different way (see below) by updating the assembly plugin dependency to 3.1.1:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.31.0</version>
    <!-- ... -->
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.1</version>
        </dependency>
    </dependencies>
</plugin>

@rohanKanojia
Copy link
Member

@daniel-huss : Thanks for your feedback. Could you please raise a PR to update this dependency if you have time?

@daniel-huss
Copy link

Unfortunately, using version 3.1.1 breaks my build in a different way. The assembly plugin now reports an empty set of dependencies, which breaks <dependencySet>:

[DEBUG] Dependencies for project: my-group:my-docker-image:pom:0.4.0-SNAPSHOT are:

(just an empty line)

Removing the plugin <dependencies> section reverts the situation to

[DEBUG] Dependencies for project: my-group:my-docker-image:pom:0.4.0-SNAPSHOT are:
my-group:my-app-standalone:jar:0.4.0-SNAPSHOT:provided
[DEBUG] Resolving project dependencies transitively.
...

However, disabling our maven-enforcer-plugin execution has fixed the issue completely for me:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-maven-3</id><!-- Defined in our base POM  -->
                        <phase>none</phase>
                    </execution>
                </executions>
                <!-- Note that using <configuration><skip>true  is not enough! -->
            </plugin>

@sdehors-ibm
Copy link

Experienced the same issue with docker-maven-plugin 0.40.2, fixed it by forcing the assembly plugin version to 3.1.1.

@rhuss
Copy link
Collaborator

rhuss commented Aug 11, 2022

@rohanKanojia do you think we would be able to update the assembly plugin without breaking something ?

@rohanKanojia rohanKanojia self-assigned this Aug 11, 2022
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Aug 11, 2022
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Aug 12, 2022
@rohanKanojia rohanKanojia removed their assignment Oct 14, 2022
@slawekjaranowski
Copy link
Contributor

slawekjaranowski commented Oct 17, 2022

Bug is in docker-m-p - fixed in mentioned PR

rohanKanojia pushed a commit that referenced this issue Oct 20, 2022
Default dependencies resolutions for Mojo is NONE.

When Mojo doesn't explicit required dependencies resolutions - plugins executed before can have impact on build.

Eg.
maven-enforcer-plugin only requires dependencies collections.
If we have only m-enforcer-p like in pom packaging, resolved artifacts are not downloaded.
It can cause NPE in m-assembly-p for missing files.

Fix #1146

Signed-off-by: Slawomir Jaranowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants