简体   繁体   English

Maven构建-对核心类的依赖

[英]Maven build - dependancy on core classes

I have two projects I am working on which share some common code - I am putting this common code in to a new project called Core. 我有两个正在工作的项目,它们共享一些通用代码-我将此通用代码放入了一个名为Core的新项目中。

Both my projects use maven to build, and my core classes will also use maven. 我的两个项目都使用maven进行构建,而我的核心类也将使用maven。 In Eclipse how do I configure maven to do a maven build of the core classes and then use these in the build for my two other applications? 在Eclipse中,如何配置maven以对核心类进行maven构建,然后在构建中将其用于其他两个应用程序?

Is there some prebuilt rule I need to specify - for example build this project, however, go build core first and use the output of that for this. 我是否需要指定一些预先构建的规则-例如,构建该项目,但是,首先构建核心,并为此使用输出。

Hope that makes some sort of sense. 希望这有道理。

You can add a dependency to Core artifact in your project. 您可以在项目中为Core工件添加依赖项。

If you use M2E Eclipse plug-in , workspace artifacts are quite easy to reference in the Maven editor. 如果使用M2E Eclipse插件 ,则在Maven编辑器中很容易引用工作空间工件。

The only condition for this kind of dependency to work is that dependent artifact must be retrievable from a maven repository (eventually putting it to the local maven repository through install goal). 这种依赖项起作用的唯一条件是,必须能够从Maven存储库中检索到依赖的工件(最终通过install目标将其放入本地Maven存储库中)。

You could add a parent pom, with modules 您可以添加带有模块的父pom

<project>
    <groupId>com.mypackage</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>parent</name> 
    <packaging>pom</packaging>
...
<modules>
  <module>Core</module>
  <module>MyModuleA</module>
  <module>MyModuleB</module>
</modules>
...
</project>

And then just add your dependency in MyModuleA and MyModuleB like a normal dependency 然后像正常依赖一样在MyModuleA和MyModuleB中添加您的依赖

<dependency>
    <groupId>com.mypackage</groupId>
    <artifactId>Core</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM