gpt4 book ai didi

maven-3 - 自定义Maven打包,不包含传递依赖项

转载 作者:行者123 更新时间:2023-12-04 04:33:05 25 4
gpt4 key购买 nike

我正在玩一些非Java构件的自定义Maven 3打包插件,并且在使传递性依赖项起作用时遇到问题。我定义了三个项目,分别是model,model-impl和cli,它们的依赖关系如下:

cli
model-impl
model

我的自定义生命周期插件在每个项目中都会被调用,并且我可以成功地构建模型和模型隐喻。对于每个项目,预期的工件都存储在我的本地资源库中。 cli但是失败了,因为我没有在Mojo中将模型作为依赖项。我不完全确定这是我的代码中存在的问题,因为即使使用mvndependency:dependency-tree也不会显示完整的依赖关系层次结构:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.corp.nodes:myproj-cli >-----------------------
[INFO] Building myproj Test 1.0.0-SNAPSHOT
[INFO] --------------------------------[ myproj ]--------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myproj-cli ---
[INFO] com.corp.nodes:myproj-cli:myproj:1.0.0-SNAPSHOT
[INFO] \- com.corp.:myproj-model-impl:myproj:1.0.0-SNAPSHOT:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

在这里,我希望我能看到每个项目都有三层的树。

这是我的自定义插件中定义的components.xml:
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>myproj</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<initialize>com.corp.maven:myproj-plugin:unpackageDependencies</initialize>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>com.corp.maven:myproj-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>com.corp.maven:myproj-plugin:package</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>myproj</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>myproj</type>
<extension>myproj</extension>
<packaging>myproj</packaging>
<addedToClasspath>true</addedToClasspath>
<includesDependencies>true</includesDependencies>
</configuration>
</component>
</components>
</component-set>

所有项目POM的包装都设置为myproj,所有依赖项的类型都设置为myproj。这是cli项目的pom:
<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>com.corp.arthur.nodes</groupId>
<artifactId>myproj-cli</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>myproj</packaging>

<name>myproj Test</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.corp.arthur</groupId>
<artifactId>myproj-model-impl</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>myproj</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.corp.maven</groupId>
<artifactId>myproj-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

impl项目的POM看起来很相似。任何想法就是我所缺少的吗?

最佳答案

最后,通过跟踪DefaultDependencyCollector类的源找出了发生了什么。原来,我需要在我的components.xml中将includesDependencies设置为 false 。发生的事情是,依赖关系收集器看到该标志为true,这意味着依赖关系已包含在工件中,因此没有通过它们进行递归。将其设置为false,它会递归,并且得到预期的行为。

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.corp.nodes:myproj-cli >------------------
[INFO] Building myproj Test: CLI Node 1.0.0-SNAPSHOT
[INFO] --------------------------------[ myproj ]--------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myproj-cli ---
[INFO] com.corp.nodes:myproj-cli:myproj:1.0.0-SNAPSHOT
[INFO] \- com.corp:myproj-model-impl:myproj:1.0.0-SNAPSHOT:compile
[INFO] \- com.corp:myproj-model:myproj:1.0.0-SNAPSHOT:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

关于maven-3 - 自定义Maven打包,不包含传递依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50418101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com