我从一个我想使用的开源项目的现有maven构建开始。它建立得很好。
我向父pom添加了一个新的配置文件(standalone-server-and-client),希望使用maven-assembly-plugin构建两个jar,一个用于客户端,一个用于服务器,每个包含所有依赖项和在pom中指定的主类。在激活配置文件的情况下运行构建时,都会构建两个jar。
但是,除了清单外,它们都是空的。什么可能导致这种行为?最初的pom还包括maven-jar-plugin,这些可能会互相混乱吗?
这是完整的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>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo</artifactId>
<version>0.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Eclipse Milo - OPC-UA (IEC 62541)</name>
<description>An open source implementation of OPC-UA (IEC 62541).</description>
<url>https://github.com/eclipse/milo</url>
<scm>
<url>https://github.com/eclipse/milo</url>
<connection>scm:git:git://github.com/eclipse/milo.git</connection>
<developerConnection>scm:git:git@github.com:eclipse/milo.git</developerConnection>
<tag>HEAD</tag>
</scm>
<developers>
<developer>
<id>kevinherron</id>
<name>Kevin Herron</name>
<email>kevinherron@gmail.com</email>
</developer>
</developers>
<licenses>
<license>
<name>Eclipse Public License 1.0</name>
<url>https://eclipse.org/org/documents/epl-v10.php</url>
<distribution>repo</distribution>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://eclipse.org/org/documents/edl-v10.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<modules>
<module>build-tools</module>
<module>milo-examples</module>
<module>opc-ua-stack</module>
<module>opc-ua-sdk</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<prerequisites>
<maven>3.0.5</maven>
</prerequisites>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<failOnError>false</failOnError>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<extensions>false</extensions>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>javadoc-and-source</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<failOnError>false</failOnError>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>standalone-server-and-client</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>build-client</id>
<configuration>
<archive>
<manifest>
<mainClass>org.eclipse.milo.examples.client.SecureClientStandalone</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-client</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>build-server</id>
<configuration>
<archive>
<manifest>
<mainClass>org.eclipse.milo.examples.server.SecureServerStandalone</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-server</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>milo/checkstyle.xml</configLocation>
<excludes>
**/Ua*Loader*,
**/org/eclipse/milo/opcua/stack/core/types/structured/*,
**/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
**/org/eclipse/milo/opcua/sdk/core/CefactEngineeringUnits.java,
**/org/eclipse/milo/opcua/sdk/client/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/client/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/client/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/client/model/types/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
**/org/eclipse/milo/opcua/stack/core/Identifiers.java,
**/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
**/org/eclipse/milo/opcua/stack/core/StatusCodes.java,
**/org/opcfoundation/opcua/binaryschema/*
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>build-tools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>milo/checkstyle.xml</configLocation>
<excludes>
**/Ua*Loader*,
**/org/eclipse/milo/opcua/stack/core/types/structured/*,
**/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
**/org/eclipse/milo/opcua/sdk/core/CefactEngineeringUnits.java,
**/org/eclipse/milo/opcua/sdk/client/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/client/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/client/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/client/model/types/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
**/org/eclipse/milo/opcua/stack/core/Identifiers.java,
**/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
**/org/eclipse/milo/opcua/stack/core/StatusCodes.java,
**/org/opcfoundation/opcua/binaryschema/*
</excludes>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>generate-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Import-Package>
com.sun.management.*;resolution:=optional,
!javax.annotation.*,
*
</Import-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>milo/checkstyle.xml</configLocation>
<excludes>
**/Ua*Loader*,
**/org/eclipse/milo/opcua/stack/core/types/structured/*,
**/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
**/org/eclipse/milo/opcua/sdk/client/api/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/client/api/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/client/api/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/client/api/model/types/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
**/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
**/org/eclipse/milo/opcua/stack/core/Identifiers.java,
**/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
**/org/eclipse/milo/opcua/stack/core/StatusCodes.java
</excludes>
</configuration>
</plugin>
</plugins>
</reporting>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>
答案 0 :(得分:0)
一位有用的评论者提供的提示证明是正确的:
它在<packaging>pom</packaging>
的pom中无效。我将配置文件向下移动了两个级别,进入模块,其中没有指定包装,因此使用了默认包装jar
。
以下是我的工作配置(与服务器模块一样)。它与我在另一个pom中的配置相同(减去服务器部分),但它在这里工作。另外,请确保现在查看正确的目标文件夹 - 它将位于模块的目标文件夹中。
<?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>org.eclipse.milo</groupId>
<artifactId>milo-examples</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>client-examples</artifactId>
<profiles>
<profile>
<id>standalone-server-and-client</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>build-client</id>
<configuration>
<archive>
<manifest>
<mainClass>org.eclipse.milo.examples.client.SecureClientStandalone</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>milo-opcua-client</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-client</artifactId>
<version>0.2.0-SNAPSHOT</version>
</dependency>
<!-- Redeclare our dependency on Bouncy Castle
because we use SelfSignedCertificateBuilder -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>server-examples</artifactId>
<version>0.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
</project>