如何在不部署jar的情况下在Maven中配置子项目依赖项?
我用谷歌搜索了一下,似乎没有人能回答,但似乎这是一件基本的事情,应该有可能.
I googled this and it seems that no one has an answer, yet it seems like such an elementary thing that it should be possible.
我具有以下项目结构:
parent
---sub-project1
---sub-project2
sub-project2需要具有sub-project1作为依赖项.
sub-project2 needs to have sub-project1 as a dependency.
所以我在sub-project2的pom中有这个
So I have this in sub-project2's pom:
<dependencies>
<dependency>
<artifactId>sub-project1</artifactId>
<groupId>mygroup</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
....
当我这样做时,Maven尝试下载sub-project1.jar文件,该文件不存在,因为尚未准备好回购.
When I do this, Maven tries to dowload the sub-project1.jar file, which does not exist because it's not ready for the repo yet.
我试图将<scope>import</scope>
放在依赖项中,但这也不起作用-结果相同.
I tried to put a <scope>import</scope>
in the dependency, but that didn't work either -- same result.
那我该怎么做才能使Maven在构建sub-project2时查看sub-project1?
So what do I have to do to get Maven to look at sub-project1 when building sub-project2?
编辑:以下是一些pom片段:
EDIT Here are some pom snippets:
父母:
<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>
<prerequisites>
<maven>2.0.9</maven>
</prerequisites>
<modules>
<module>sub-project1</module>
<module>sub-project2</module>
</modules>
....
子项目1:
<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">
<parent>
<artifactId>parent</artifactId>
<groupId>mygroup</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sub-project1</artifactId>
....
sub-project2:
sub-project2:
<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">
<parent>
<artifactId>parent</artifactId>
<groupId>mygroup</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sub-project1</artifactId>
<dependencies>
....
<dependency>
<artifactId>sub-project2</artifactId>
<groupId>mygroup</groupId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>
</dependencies>
当我在父母上得到mvn clean install
时遇到的错误是:
The error I'm getting when I got mvn clean install
on the parent is:
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
有很多类/包未找到错误
With a lot of classes/package not found errors
您应该在父级拥有一个主pom,在其中列出项目的模块.
You should have a master pom at parent's level, in which you will list the modules of your project.
<modules>
<module>sub-project1</module>
<module>sub-project2</module>>
</modules>
在每个子项目中,您都必须引用您的父母:
In each subproject you have to reference your parent:
<parent>
<artifactId>parent</artifactId>
<groupId>mygroup</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
就像您一样,您可以指定项目之间的依赖关系.我认为您已经错过了我描述的一些步骤.
And you specify the dependencies between the project just as you did. I think you've missed some of the steps I've described.
您应该在父级别下发布 mvn全新安装.
you should issue your mvn clean install at the parent level.