Skip to content

Commit

Permalink
BuildMojo should require dependencies resolutions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
slawekjaranowski authored and rohanKanojia committed Oct 20, 2022
1 parent 83cae7e commit be517e1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- image/squash option is taken into account when using buildx ([1605](https://github.com/fabric8io/docker-maven-plugin/pull/1605)) @kevinleturc
- Allow having build args with same name but different value in various sources, which are overriden in the order of precedence in resulting build args map ([1407](https://github.com/fabric8io/docker-maven-plugin/issues/1407)) @pavelsmolensky
- Use double for `docker.cpus` property and interpret this value in the same way as Docker config option `--cpus` ([1609](https://github.com/fabric8io/docker-maven-plugin/pull/1609)) @vjuranek
- NPE from Assembly plugin when POM packaging is used ([1146](https://github.com/fabric8io/docker-maven-plugin/issues/1146)) @slawekjaranowski

* **0.40.2** (2022-07-31):
- Plugin doesn't abort building an image in case Podman is used and Dockerfile can't be processed ([1562](https://github.com/fabric8io/docker-maven-plugin/issues/1512)) @jh-cd
Expand Down
68 changes: 68 additions & 0 deletions it/build-pom-packaging/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-parent</artifactId>
<version>0.41-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dmp-it-build-pom-packaging</artifactId>
<version>0.41-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Docker Maven Plugin Integration Test - pom packaging and plugin which use dependencies collections</description>

<dependencies>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<images>
<image>
<name>dmp-pom-packaging</name>
<build>
<from>fabric8/java-centos-openjdk8-jdk:1.5.6</from>
<assemblies>
<assembly>
<descriptorRef>dependencies</descriptorRef>
</assembly>
</assemblies>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-build</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>

<plugin>
<!-- m-enforcer-p requires dependencies collections only - artifacts files are not downloaded -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
1 change: 1 addition & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<packaging>pom</packaging>

<modules>
<module>build-pom-packaging</module>
<module>builder</module>
<module>buildx</module>
<module>buildx-contextdir</module>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/fabric8/maven/docker/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

import io.fabric8.maven.docker.access.AuthConfig;
import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.assembly.BuildDirs;
import io.fabric8.maven.docker.config.BuildImageConfiguration;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.BuildService;
import io.fabric8.maven.docker.service.BuildXService;
import io.fabric8.maven.docker.service.ImagePullManager;
import io.fabric8.maven.docker.service.JibBuildService;
import io.fabric8.maven.docker.service.RegistryService;
Expand All @@ -28,14 +26,15 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* Mojo for building a data image
*
* @author roland
* @since 28.07.14
*/
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL)
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST)
public class BuildMojo extends AbstractBuildSupportMojo {

public static final String DMP_PLUGIN_DESCRIPTOR = "META-INF/maven/io.fabric8/dmp-plugin";
Expand Down

0 comments on commit be517e1

Please sign in to comment.