gpt4 book ai didi

eclipse - 使用 Eclipse 构建 Maven 多模块

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

我正在转向 Maven 多模块构建。

我的项目结构如下:

MyProject
|-->MyProject-Core
| |->pom.xml (packaging jar)
|-->MyProject-Assets
| |->pom.xml (packaging jar)
|-->MyProject-Libs
| |->pom.xml (packaging jar)
|-->pom.xml (packaging pom, aggregator)

MyProject 是一个 Maven Eclipse 项目,由 M2E 构建。

我将 MyProject-Core/src/main/java 添加为 Eclipse 源文件夹,但是由于我将父 pom 中的依赖项部分更改为 dependencyManagement,所以我从 Eclipse 中得到了构建错误。手动调用 mvn package 仍然可以正常工作。

如何配置Eclipse来正确解析核心pom的依赖?

我仍然可以将依赖项添加到父 pom 作为 scope:provided,但这是最好的解决方案吗?

父类:

<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence
on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
exec-maven-plugin
</artifactId>
<versionRange>
[1.2,)
</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<index>true</index>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<packageName>com.example</packageName>
<addDefaultImplementationEntries>true
</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<SVN-Revision>${workingCopyDirectory.revision}</SVN-Revision>
</manifestEntries>
<compress>false</compress>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>MyProject-core</module>
</modules>
</project>

核心 Pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
<artifactId>MyProject-Core</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
</build>
</project>

最佳答案

我尝试了很多配置,但 M2E 无法将子模块识别为自己的项目,或者父模块项目无法识别子模块的更改。

现在我创建了几个 Eclipse 项目,每个 Maven 项目一个,它运行良好。

关于eclipse - 使用 Eclipse 构建 Maven 多模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16186028/

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