我們有 un maven 多模塊專案,我們想生成一個檔案夾中每個 maven 模塊的文本表示。
是否可以 ?
uj5u.com熱心網友回復:
假設你有一個這樣的父模塊:
<?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] ------------------------------------------------------------------------
這基本上就是你所需要的。您還可以從子模塊檔案夾中運行相同的命令,從而分別獲取特定模塊的樹。
uj5u.com熱心網友回復:
感謝您的回答,但是否可以為每個模塊生成單獨的樹到指定的檔案夾中?(我們希望在檔案中鏈接這些樹并在 maven 階段重繪 這些樹)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/321401.html
標籤:行家
上一篇:如何使用maven為Micronaut創建可執行的jar檔案?
下一篇:Maven從一個包運行所有測驗
