我们可以在一个多模块项目的文件夹中单独生成maven依赖树吗?



我们有一个maven多模块项目,我们想在一个文件夹中生成每个maven模块的文本表示。

可能吗?

假设你有一个这样的父模块:

<?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.example</groupId>
<artifactId>deps</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>junit-module</module>
<module>testng-module</module>
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
<version>5.0.0-ALPHA</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

和两个子模块:

<?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.example</groupId>
<artifactId>junit-module</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.example</groupId>
<artifactId>deps</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
</dependency>
</dependencies>
</project>

<?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.example</groupId>
<artifactId>tesng-module</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.example</groupId>
<artifactId>deps</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
</dependencies>
</project>
所以如果你在父文件夹下运行mvn dependency:tree你会得到:
[INFO] ----------------------< org.example:junit-module >----------------------
[INFO] Building junit-module 1.0-SNAPSHOT                                 [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ junit-module ---
[INFO] org.example:junit-module:jar:1.0-SNAPSHOT
[INFO] - org.junit:junit5-engine:jar:5.0.0-ALPHA:compile
[INFO]    +- org.junit:junit5-api:jar:5.0.0-ALPHA:compile
[INFO]    |  +- org.opentest4j:opentest4j:jar:1.0.0-ALPHA:compile
[INFO]    |  - org.junit:junit-commons:jar:5.0.0-ALPHA:compile
[INFO]    - org.junit:junit-engine-api:jar:5.0.0-ALPHA:compile
[INFO] 
[INFO] ----------------------< org.example:tesng-module >----------------------
[INFO] Building tesng-module 1.0-SNAPSHOT                                 [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ tesng-module ---
[INFO] org.example:tesng-module:jar:1.0-SNAPSHOT
[INFO] - org.testng:testng:jar:7.4.0:compile
[INFO]    +- com.beust:jcommander:jar:1.78:compile
[INFO]    - org.webjars:jquery:jar:3.5.1:compile
[INFO] ------------------------------------------------------------------------

基本上就是你需要的。您也可以在子模块文件夹中运行相同的命令,从而单独获得特定模块的树。

谢谢您的回答,但是否可以为每个模块生成单独的树到指定的文件夹?(我们希望在文档中链接这些树,并在maven阶段刷新这些树)

相关内容

  • 没有找到相关文章

最新更新