我有一些复杂的项目结构,我想通过Maven来构建。我正在使用本地存储库(.m2/repository
),所以请记住这一点!在讨论这个问题之前,我想先分享一下我目前的结构:
+- pom.xml
+- runtimeProject1
| +- pom.xml
+- runtimeProject2
| +- pom.xml
+- runtimeProject3
| +- pom.xml
+- sharedProjects
| +- pom.xml
| +- sharedProject1
| | +- pom.xml
| +- sharedProject2
| | +- pom.xml
| +- sharedProject3
| +- pom.xml
+- coreProjects
+- pom.xml
+- coreProject1
| +- pom.xml
+- coreProject2
| +- pom.xml
+- coreProject3
+- pom.xml
总之,我的工作区有两个子目录,其中有与自己的任务相关的模块,以及应该使用core
和shared.
项目的运行时项目。每个项目都有一个pom.xml
文件,正如您所看到的,我也为父母提供了pom.xml
。一切都是通过本地存储库完成的,所以请记住这一点。
现在,在mvn install
和coreProjects
目录下分别运行很好。我看到了成功的结果,说一切都好。当我从根文件夹(顶层pom.xml
)运行相同的命令时,就会出现这个问题。我面临以下警告:
[WARNING] Some problems were encountered while building the effective model for runtimeProjects:runtimeProject1:jar:1.0.0
[WARNING] 'dependencies.dependency.systemPath' for coreProject:com.google.protobuf:jar should not point at files within the project directory, ${project.basedir}/../coreProject/com.google.protobuf/protobuf-java-2.5.0.jar will be unresolvable by dependent projects @ line 31, column 22
[WARNING] 'dependencies.dependency.systemPath' for sharedProject:org.boofcv:jar should not point at files within the project directory, ${project.basedir}/../sharedProject/org.boofcv/GeoRegression.jar will be unresolvable by dependent projects @ line 43, column 22
[WARNING] 'dependencies.dependency.systemPath' for sharedProject:org.boofcv:jar should not point at files within the project directory, ${project.basedir}/../sharedProject/org.boofcv/BoofCV.jar will be unresolvable by dependent projects @ line 50, column 22
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: sharedProject:org.boofcv:jar -> duplicate declaration of version 1.0.0.qualifier @ line 45, column 16
[WARNING] 'dependencies.dependency.systemPath' for sharedProject:javax.vecmath:jar should not point at files within the project directory, ${project.basedir}/../sharedProject/javax.vecmath/vecmath.jar will be unresolvable by dependent projects @ line 62, column 22
然后错误地说出了某些package do not exist
,我猜这是由这个复杂因素造成的。
我想我需要在这里修改一个pom.xml
,但不知道是哪一个,也不知道如何修改。
更新:--我决定分享使用某些.jar
文件作为依赖关系的方式,如下所示:
<dependency>
<groupId>coreProjects</groupId>
<artifactId>com.google.protobuf</artifactId>
<version>2.5.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../coreProjects/com.google.protobuf/protobuf-java-2.5.0.jar</systemPath>
</dependency>
<dependency>
<groupId>coreProjects</groupId>
<artifactId>org.apache.felix</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../coreProjects/org.apache.felix/felix.jar</systemPath>
</dependency>
注意,这些文件在coreProjects
和sharedProjects
文件夹下工作得很好。只是不属于runtimeProject
,因此我提出了问题。
更新2:
好的,在收到评论员的大量警告“不要使用systemPath
和system
作为作用域”之后,我重新构建了我的构建策略,现在我没有使用任何与系统相关的东西。然而,这个问题仍然存在。现在,我指定了如下所示的依赖项(因为您可以看到没有与路径相关的内容):
<dependency>
<groupId>coreProjects</groupId>
<artifactId>coreProject2</artifactId>
<version>1.0.0.qualifier</version>
</dependency>
<dependency>
<groupId>coreProjects</groupId>
<artifactId>coreProject1</artifactId>
<version>1.0.0.qualifier</version>
</dependency>
<dependency>
<groupId>sharedProjects</groupId>
<artifactId>org.boofcv</artifactId>
<version>[1.0,)</version>
</dependency>
所以我们是安全的,我相信。上述警告已经消失。到目前为止,我只得到package does not exist
错误。这很奇怪,因为它所抱怨的包是在根的pom.xml
文件中引用的。例如,其中一个错误是:
package org.osgi.framework does not exist
然而,另一件事引起了我的注意。我遇到的另一个错误不是直接给出包的名称,而是给出包的一部分。例如,如果包名为somePackageName
,则错误表示somePackageName.somePart does not exist
。所以,这不是整个方案,而是其中的一部分,这使我更加困惑。
原因可能是什么?
发布于 2016-07-05 10:18:45
好吧,我好像犯了一个简单的错误。我的proto
文件在错误的目录下转换为java
文件,导致package does not exist
错误。因此,如果您看到此错误,如果您正在以某种方式使用协议缓冲区,请检查您的pom.xml
中的antrun-plugin
。确保它在正确的目录下操作。在这里,我为我的proto文件生成共享我的antrun-plugin
部件。请您看到,目录确实很重要,因此要非常小心。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="src-gen"/>
<exec executable="protoc">
<arg value="--java_out=src-gen"/>
<arg value="proto/file1.proto"/>
<arg value="proto/ros/file1.proto"/>
<arg value="proto/ros/file2.proto"/>
<arg value="proto/environment/file1.proto"/>
</exec>
</tasks>
<sourceRoot>src-gen</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
https://stackoverflow.com/questions/38123749
复制相似问题