[英]How to reference a non-maven project (in eclipse workspace) from a maven project?
我正在開發一個新項目,它是一個產品的插件。
我使用maven來構建我的插件(zip),但我需要引用在Eclipse工作區中定義的產品的源代碼。 但是這個源代碼不是由Maven管理的,我不想遷移它。
是否可以通過任何方式引用此工作空間項目? (maven插件,解決方法歡迎)。
Eclipse中的編譯只需要依賴項,但不會在插件本身中打包( provided
范圍)。
我在Eclipse中也有m2e,我想在進行“Maven更新”時保留這個配置。
更新:我正在尋找一個解決方案,它將在命令行上使用mvn clean install
,因為我希望能夠從CI平台執行構建(例如Jenkins)
只需使用Project - > Properties - > Java Build Path - > Projects - > Add
如果需要在Eclipse外部編譯它,可以在物理jar位置添加依賴項:
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/test.jar</systemPath>
</dependency>
您可以考慮使用antrun插件在鏈接到編譯階段的外部項目中觸發源代碼的編譯。 您甚至可以將.class文件復制到目標文件夾中,以便運行時類路徑找到它們
因為我已經編譯了源代碼而且我不需要重新編譯它們(或修改任何東西)我決定使用pom程序集打包它們。
我創建了一個單獨的項目(在與我的插件開發項目相同的父項下),類似於openemm-src:
Parent project (openemm-plugin-dev)
|- plugin-1
|- plugin-2
|- openemm-src
|- pom.xml
openemm-src
項目的pom.xml如下所示:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>openemm.plugin.dev</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>openemm-src</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>OpenEMM Source Code Library</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/src-plugin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<xecution>
</executions>
</plugin>
</plugins>
</build>
</project>
和文件src/assembly/src-plugin.xml
:
<assembly>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>build/classes</directory>
<outputDirectory></outputDirectory>
</fileSet>
</fileSets>
</assembly>
在此之后,我從兄弟姐妹項目中引用了這樣的jar:
<dependency>
<groupId>openemm.plugin.dev</groupId>
<artifactId>openemm-src</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
此解決方案看起來更像是一種解決方法,但這是因為OpenEMM項目沒有任何“插件模板項目”可以使用Maven進行管理。
請注意,這只是一個部分配置,我還要引用Agnitas庫,它們不包含所有源代碼(兩者都是編譯我的代碼所必需的)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.