1

据我了解构建流程:

  1. maven-assembly-plugin构建/target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar

  2. maven-jar-plugin构建/target/my-artifact-1.0-SNAPSHOT.jar(不确定我们为什么需要它)

  3. docker-maven-plugin假设组装 artifact-with-dependencies /target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar

然而,由于某种原因,它选择了错误的 jar 人工制品。

我错过了什么?如何让它发挥作用?

pom.xml

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.20.1</version>
    <extensions>true</extensions>
    <configuration>
        <images>
            <image>
                <name>my-artifact</name>
                <build>
                    <from>java:8-jre</from>
                    <volumes>
                        <volume>/target</volume>
                    </volumes>
                    <entryPoint>
                        <exec>
                            <arg>java</arg>
                            <arg>-jar</arg>
                            <arg>/target/my-artifact-1.0-SNAPSHOT-jar-with-dependencies.jar</arg>
                        </exec>
                    </entryPoint>
                    <assembly>
                        <descriptorRef>artifact-with-dependencies</descriptorRef>
                        <targetDir>/target</targetDir>
                        <mode>dir</mode>
                        <!--<basedir>/target</basedir>-->
                    </assembly>
                </build>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <id>docker-build</id>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
        <execution>
            <id>docker:start</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>docker:stop</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>create-archive</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <archive>
            <manifest>
                <mainClass>Client</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>Client</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>
4

1 回答 1

1

要引用文档,:

     <descriptorRef>artifact-with-dependencies</descriptorRef>

将添加名为 ${project.build.finalName}.${artifact.extension} 的已创建工件和 targetDir 中的所有 jar 依赖项(默认为 /maven)。

这不是你想要的。

我想你想要的是将程序集自定义为如下内容:

<assembly>
 <targetDir>/target</targetDir>
 <inline>
    <fileSets>
      <fileSet>
        <directory>${project.basedir}/target/</directory>
        <outputDirectory>.</outputDirectory>
        <includes>
             <include>project-name-version-classifier-jar-with-dependencies.jar</include> 
         </includes>
         </fileSet>
       </fileSets>
     </inline>
   </assembly>

加分点:看看Jib,如果您正在为 Java 项目构建映像,它可能更适合您的需求。

于 2019-04-09T08:36:30.463 回答