projectHelper.attachArtifact 和 project.getArtifact().setFile 之间的区别
Difference between projectHelper.attachArtifact and project.getArtifact().setFile
我目前在使用命令行执行 MUnit 测试时遇到问题。
我遇到了 "duplicate project artifact assignment" 将 1.2 版的 mule-domain-maven-plugin that was fixed here 与 1.3 版一起使用的问题。删除这行代码会在 mule-domain-config.xml when 运行 my MUnit.
上导致 FileNotFoundException
反编译代码后,我可以看到 1.2(适用于我的 MUnit)有 2 行代码:
this.projectHelper.attachArtifact(this.project, "zip", domain);
this.project.getArtifact().setFile(domain);
我可以看到1.3只有这一行:
this.projectHelper.attachArtifact(this.project, "zip", domain);
有人知道 this.projectHelper.attachArtifact(this.project, "zip", domain);
和 this.project.getArtifact().setFile(domain);
之间的区别以及如何解决这个问题吗?
区别与主神器和附属神器之间的区别相同。
首先,简单地说,工件是一个包含指向它的 Maven coordinates 的对象(组 ID / 工件 ID / 版本 / 分类器 / 类型),一个存储库在哪里解析它或在哪里解决了,还有一个文件,就是实际使用/下载/上传的具体文件。
除 POM 项目外,Maven 项目会生成一个主工件。这取决于它的包装;例如,打包为 jar
的项目将创建一个主 JAR 工件,其文件包含项目的所有 类,打包为 war
的项目将创建 Web 应用程序.此外,项目本身与其 POM 文件相关联;这意味着一个项目不仅有一个用于其主要工件的文件,而且还具有对创建它的 POM 文件的引用。只有打包pom
的项目不会创建main artifact;这是因为此类项目是父项目或聚合项目,包含要在多个项目之间共享的构建逻辑,但它们不会产生主要可交付成果。
除此之外,项目还有附加的或次要的工件。它们对应于在项目构建期间也会生成的附加工件,并且与主要工件的不同之处在于它们的 classifier and/or 类型,当然还有它们的实际文件。这些额外的工件与主要工件一起安装和部署。例如,一个典型的打包项目 jar
也会将其 Javadoc 和源代码生成为 JAR 文件,作为具有分类器 javadoc
和 sources
的附加工件。因此,打包 pom
的项目只能有附加工件,因为它没有主工件。最后,完全允许有一个没有附加工件的项目;只有主要的(或者 none 在 pom
项目的情况下)会被部署。
在 Maven 插件中,所有这些注意事项归结为以下几点:
- 使用
project.getArtifact()
, as an Artifact
检索项目的主要工件。
project.getArtifact().setFile(...)
sets the actual file of the main artifact of the project. Again, for a project of packaging jar
, this would be the actual JAR file that was generated on-disk. Concrete example: it is what the Maven JAR plugin does.
MavenProjectHelper
component is used to attach artifacts to the project. projectHelper.attachArtifact(project, "zip", file);
would attach an artifact of type ZIP to the given project, with no classifier, and whose file is the given file. There is an overload to attach an artifact with a classifier. Concrete example: it is what the Maven Assembly Plugin does 当它被配置为附加它产生的工件时。
project.setFile(file)
设置创建它的Maven项目的POM文件。
举个例子,我们可以考虑部署的工件under org.mule.tools.maven
in Central. Under the artifact id mule-maven-plugin
,有多个文件:
mule-maven-plugin-2.1.jar
是主要的工件文件,
- 由 POM 文件创建
mule-maven-plugin-2.1.pom
,
- 而
mule-maven-plugin-2.1-javadoc.jar
和 mule-maven-plugin-2.1-sources.jar
附有各自的分类器。
作为第二个示例,考虑工件 ID mule-esb-maven-tools
。唯一部署的文件(散列文件除外)是 mule-esb-maven-tools-1.1.pom
。这是完全正常的,因为它是一个 POM 项目,所以它没有主要工件(没有部署 JAR 或其他);只有项目的 POM 文件,没有附加的工件。
我目前在使用命令行执行 MUnit 测试时遇到问题。
我遇到了 "duplicate project artifact assignment" 将 1.2 版的 mule-domain-maven-plugin that was fixed here 与 1.3 版一起使用的问题。删除这行代码会在 mule-domain-config.xml when 运行 my MUnit.
上导致 FileNotFoundException反编译代码后,我可以看到 1.2(适用于我的 MUnit)有 2 行代码:
this.projectHelper.attachArtifact(this.project, "zip", domain);
this.project.getArtifact().setFile(domain);
我可以看到1.3只有这一行:
this.projectHelper.attachArtifact(this.project, "zip", domain);
有人知道 this.projectHelper.attachArtifact(this.project, "zip", domain);
和 this.project.getArtifact().setFile(domain);
之间的区别以及如何解决这个问题吗?
区别与主神器和附属神器之间的区别相同。
首先,简单地说,工件是一个包含指向它的 Maven coordinates 的对象(组 ID / 工件 ID / 版本 / 分类器 / 类型),一个存储库在哪里解析它或在哪里解决了,还有一个文件,就是实际使用/下载/上传的具体文件。
除 POM 项目外,Maven 项目会生成一个主工件。这取决于它的包装;例如,打包为 jar
的项目将创建一个主 JAR 工件,其文件包含项目的所有 类,打包为 war
的项目将创建 Web 应用程序.此外,项目本身与其 POM 文件相关联;这意味着一个项目不仅有一个用于其主要工件的文件,而且还具有对创建它的 POM 文件的引用。只有打包pom
的项目不会创建main artifact;这是因为此类项目是父项目或聚合项目,包含要在多个项目之间共享的构建逻辑,但它们不会产生主要可交付成果。
除此之外,项目还有附加的或次要的工件。它们对应于在项目构建期间也会生成的附加工件,并且与主要工件的不同之处在于它们的 classifier and/or 类型,当然还有它们的实际文件。这些额外的工件与主要工件一起安装和部署。例如,一个典型的打包项目 jar
也会将其 Javadoc 和源代码生成为 JAR 文件,作为具有分类器 javadoc
和 sources
的附加工件。因此,打包 pom
的项目只能有附加工件,因为它没有主工件。最后,完全允许有一个没有附加工件的项目;只有主要的(或者 none 在 pom
项目的情况下)会被部署。
在 Maven 插件中,所有这些注意事项归结为以下几点:
- 使用
project.getArtifact()
, as anArtifact
检索项目的主要工件。 project.getArtifact().setFile(...)
sets the actual file of the main artifact of the project. Again, for a project of packagingjar
, this would be the actual JAR file that was generated on-disk. Concrete example: it is what the Maven JAR plugin does.MavenProjectHelper
component is used to attach artifacts to the project.projectHelper.attachArtifact(project, "zip", file);
would attach an artifact of type ZIP to the given project, with no classifier, and whose file is the given file. There is an overload to attach an artifact with a classifier. Concrete example: it is what the Maven Assembly Plugin does 当它被配置为附加它产生的工件时。project.setFile(file)
设置创建它的Maven项目的POM文件。
举个例子,我们可以考虑部署的工件under org.mule.tools.maven
in Central. Under the artifact id mule-maven-plugin
,有多个文件:
mule-maven-plugin-2.1.jar
是主要的工件文件,- 由 POM 文件创建
mule-maven-plugin-2.1.pom
, - 而
mule-maven-plugin-2.1-javadoc.jar
和mule-maven-plugin-2.1-sources.jar
附有各自的分类器。
作为第二个示例,考虑工件 ID mule-esb-maven-tools
。唯一部署的文件(散列文件除外)是 mule-esb-maven-tools-1.1.pom
。这是完全正常的,因为它是一个 POM 项目,所以它没有主要工件(没有部署 JAR 或其他);只有项目的 POM 文件,没有附加的工件。