正如标题所说,我面临与Maven的奇怪情况。给出了我的调试过程的输出,我使用mvn install -X
命令运行:
[DEBUG] =======================================================================
[WARNING] The POM for sampleModule:sampleModule.msg:jar:1.0.0.qualifier is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for sampleModule:sampleModule.msg:1.0.0.qualifier
[ERROR] 'dependencies.dependency.systemPath' for sampleModule:org.apache.felix:jar must specify an absolute path but is ${project.basedir}/../org.apache.felix/felix.jar @
[ERROR] 'dependencies.dependency.systemPath' for sampleModule:com.google.protobuf:jar must specify an absolute path but is ${project.basedir}/../com.google.protobuf/protobuf-java-2.5.0.jar @
告诉我,我的sampleModule.msg
模块有点"不正常"。但是,有点低于我看到这一行:
[DEBUG] sampleModule:sampleModule.msg:jar:1.0.0.qualifier:compile
请注意,它说"编译"并且之后没有错误。
以下是我pom.xml
模块的sampleModule.msg
文件:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>sampleModule</groupId>
<artifactId>sampleModule.master</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>sampleModule</groupId>
<artifactId>sampleModule.msg</artifactId>
<name>sampleModule.msg</name>
<version>1.0.0.qualifier</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>sampleModule</groupId>
<artifactId>org.apache.felix</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../org.apache.felix/felix.jar</systemPath>
</dependency>
<dependency>
<groupId>sampleModule</groupId>
<artifactId>com.google.protobuf</artifactId>
<version>2.5.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../com.google.protobuf/protobuf-java-2.5.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Export-Package>sampleModule.msg</Export-Package>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/src-gen"/>
<exec executable="protoc">
<arg value="--java_out=target/src-gen"/>
<arg value="target/proto/Empty.proto"/>
<arg value="target/proto/ComponentState.proto"/>
</exec>
</tasks>
<sourceRoot>target/src-gen</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我和另一个模块有同样的问题。显示5个依赖项错误,但它编译。我有点困惑。如果我们解决这个问题,我也会摆脱另一个。
因此我的问题是,我应该认真对待这个错误吗?这个矛盾是否有原因?
答案 0 :(得分:0)
关键点是:
...,传递依赖(如果有)将无法使用:...
如果没有,那么你很幸运 - 此刻。您是否已尝试在运行时使用sampleModule.msg-...jar
?它有效吗?
(BTW,<artifactId>
中作为分隔符的点是不常的,请改用连字符。)
另见Maven / POM Reference, Dependencies:
groupId , artifactId ,版本:
...由于依赖是由Maven坐标描述的,你可能会想:“这意味着我的项目只能依赖于Maven工件!”答案是,“当然,但那是件好事。”这迫使您完全依赖Maven可以管理的依赖项。遗憾的是,有时无法从中央Maven存储库下载项目。例如,项目可能依赖于具有闭源许可证的jar,该许可证阻止其位于中央存储库中。有三种方法可以处理这种情况。
使用install插件在本地安装依赖项。 该方法是最简单的推荐方法。例如:
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar
请注意,仍然需要一个地址,只有这次你使用命令行,安装插件才会为你创建一个具有给定地址的POM。
- 创建自己的存储库并在那里部署它。 对于拥有内联网的公司而言,这是一种最受欢迎的方法,并且需要能够让每个人保持同步。有一个名为
deploy:deploy-file
的Maven目标与install:install-file
目标类似(阅读插件的目标页面以获取更多信息)。- 将依赖范围设置为
system
并定义systemPath
。 不推荐,但是,我们会解释以下内容:...
- 的 Systempath下强>:
如果依赖项scope
为system
,则仅使用 。否则,如果设置了此元素,则构建将失败。 路径必须是绝对路径,因此建议使用属性指定计算机专用路径(下面properties
上的更多内容),例如${java.home}/lib
。由于假设系统范围依赖项是先验安装的,因此Maven不会检查项目的存储库,而是检查以确保文件存在。如果没有,Maven将无法构建,并建议您手动下载并安装它。
[强调我。]