2

我正在使用描述符在 Maven 中构建程序集,并且尝试简单地执行以下操作:

  1. 包含主项目工件 (JAR) 而不进行任何重命名。
  2. 包括所有项目依赖项,重命名它们。

重命名格式:

${project.artifactId}-${project.version}.lib.${artifact.artifactId}.${artifact.extension}`

目前,我的程序集描述符如下所示:

<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>default</id>

    <formats>
        <format>tar.gz</format>
        <format>zip</format>
    </formats>

    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>/</outputDirectory>
            <excludes>
                <exclude>*:*</exclude>
            </excludes>
        </dependencySet>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>/</outputDirectory>
            <outputFileNameMapping>
                ${project.artifactId}-${project.version}.lib.${artifact.artifactId}.${artifact.extension}
            </outputFileNameMapping>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
</assembly>

不幸的是,我似乎无法让主要项目工件登陆发行版。我究竟做错了什么?

4

1 回答 1

2

您可以使用<files>块来单独包含项目工件本身:

<!-- Include the project artifact itself. -->
<files>
    <file>
        <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
        <outputDirectory>/</outputDirectory>
    </file>
</files>

<!-- Include all dependent libraries. -->
<dependencySets>
    <dependencySet>
        <useProjectArtifact>false</useProjectArtifact>
        <outputDirectory>/</outputDirectory>
        <outputFileNameMapping>${project.artifactId}-${project.version}.lib.${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
        <unpack>false</unpack>
    </dependencySet>
</dependencySets>

(因为<source>可能有一个比上面更正确的表达式,但是很难找到可用的 Maven 属性的完整列表。如果有人知道,请随时编辑!)

Lastly, as an aside, if any of your dependencies have classifiers you may want to consider adding ${dashClassifier?} to your <outputFileNameMapping> somewhere, or else the classifier will be missing from the filename.

于 2012-12-04T18:22:58.113 回答