我們有幾個遺留的 Java 專案,我們將它們轉換為 Maven 專案/模塊。以前,所有專案都是 NetBeans 專案,沒有真正的依賴項管理。外部依賴存在于公司網路驅動器上,并直接作為 JAR 包含在每個模塊的 NetBeans 專案中。對于內部依賴項,使用了簡單的專案參考。構建所有東西很痛苦,因為程式員必須以正確的順序構建所有東西。
現在,我們可以在 IntelliJ IDEA 和 NetBeans 中打開所有 Maven 模塊。但是,我無法找出以特定方式組合不同模塊和外部依賴項的最佳方式,這符合內部插件式結構。尤其是使用 NetBeans(必須可以使用兩種 IDE 進行開發)。
這是 git 存盤庫/專案結構的大致樣子。模塊的檔案夾結構是每個模塊的默認 Maven 結構。這個網站的串列功能太笨拙,所以我把它作為截圖......

我們有一個內部 maven 存盤庫,可以使用 maven 等進行構建。對于 Intellij IDEA,我可以通過自定義運行配置運行和除錯 customer1 的最終產品,該配置將所需檔案復制到所需結構中:

使用 IntelliJ IDEA,我可以除錯軟體,但我認為這種方法(我創建的自定義 IntelliJ 運行配置,直接指向所有需要的 JAR 和檔案)相當丑陋,對于 NetBeans,我找不到類似的“運行配置”機制。
所以我試圖通過創建一個新的“Customer1Runnable”Maven 專案作為一種構建描述來實作這個構建程序,它指向所有需要的 Maven 模塊。基于此,我相信我可以實作和自動化來創建所需的軟體結構。Ergo 使用 maven-assembly-plugin 將所有模塊復制到插件檔案夾中,并將模塊的所有依賴項復制到 Customer1Runnable 專案內的 lib 檔案夾中。
首先,我的假設是否正確,即這是 maven-assembly-plugin 的一個可能用例?
專案本身沒有任何源檔案,它只有一個 pom.xml 和 assembly-config.xml 描述符。我將程式集插件附加到包階段。運行mvn package命令時,所有連接的模塊都被構建,但對于程式集插件的執行,我得到以下輸出:

For starters, I only tried to include one module in the assembly descriptor. This is the XML (opicom-assembly.xml) for it:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>opicom-assembly</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>my.company.reporting:module1</include>
</includes>
</moduleSet>
</moduleSets>
</assembly>
pom.xml of Customer1Runnable 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>
<version>1.6</version>
<groupId>my.company.customer1</groupId>
<artifactId>OpicomRunnable</artifactId>
<packaging>pom</packaging>
<name>OpicomRunnable</name>
<repositories>
<repository>
<id>Company-Maven-Repo</id>
<url>file:\\\\MyCompany\TFSDrop\MavenRepo</url>
</repository>
</repositories>
<modules>
<module>../my.company.customer1.module1</module>
<module>../my.company.customer1.module2</module>
.
.
.
<module>../../MyCompany_Common/Report/my.company.reporting.module1</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>opicom-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
The pom of a module looks like this:
<?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>
<parent>
<groupId>my.company</groupId>
<artifactId>reporting</artifactId>
<version>1.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>module1</artifactId>
<version>1.3</version>
<packaging>jar</packaging>
<dependencies>
<!-- external dependencies -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<finalName>my-company-${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>../build</outputDirectory>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks for any input on what I am doing wrong here / how to achieve this with Maven.
EDIT:
As requested, here an example project as ZIP-File.

還值得注意的是,NetBeans 內部的“構建專案”、“運行專案”和“除錯專案”的配置需要稍作修改。(右鍵單擊模塊“分發”->“屬性”-> 指向“操作”
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/368611.html
上一篇:無法在IntelliJIdea中決議@org.unit.Test
下一篇:Intellij-包“javax.smartcardio”在模塊“java.smartcardio”中宣告,該模塊不在模塊圖中,但專案編譯正常
