Maven调试显示警告和错误,但最终会编译 [英] Maven debug shows warnings and errors, but eventually compiles

查看:86
本文介绍了Maven调试显示警告和错误,但最终会编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我在与Maven面对一个奇怪的处境.给定的是我的调试过程的输出,该输出是我使用mvn install -X命令运行的:

As the title puts it, I am facing a strange situation with Maven. Given is the output of my debug process, which I ran with mvn install -X command:

[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模块有点不好".但是,在下面我看到这条线:

which tells me that my sampleModule.msg module is somewhat "not-okay". However, a bit below I see this line:

[DEBUG]    sampleModule:sampleModule.msg:jar:1.0.0.qualifier:compile

请注意,它说编译",之后没有错误.

Note that it says "compile" and there is no error afterwards.

这是我的sampleModule.msg模块的pom.xml文件:

<?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个依赖项错误,但可以编译.我有点困惑.如果我们解决了这个问题,我也将摆脱另一个.

I have the same problem with another module. Shows 5 dependency errors, yet it compiles. I am kinda confused. If we solve this, I'll get rid of the other one too.

因此,我的问题是,我应该认真对待这个错误吗?有这种矛盾的原因吗?

Therefore my question is, should I take this error seriously? Is there a reason for this contradiction?

推荐答案

关键点是:

...,传递依赖项(如果有)将不可用:...

..., transitive dependencies (if any) will not be available: ...

如果没有,那么您很幸运–目前.您是否已尝试在运行时使用sampleModule.msg-...jar?可以吗?

If there aren't any, you're lucky – at the moment. Have you tried to use sampleModule.msg-...jar at runtime already? Does it work?

(顺便说一句,<artifactId>中的点作为分隔符是不常用的,请使用连字符.)

(BTW, dots as separators in the <artifactId> are unusal, use hyphens instead.)

另请参见 Maven/POM参考,依赖项:

  • groupId artifactId 版本:
    ...

  • groupId, artifactId, version:
    ...

由于依赖关系是由Maven坐标描述的,因此您可能会想:这意味着我的项目只能依赖于Maven工件!"答案是:当然,那是一件好事."这迫使您完全依赖Maven可以管理的依赖项.不幸的是,有时无法从中央Maven存储库下载项目.例如,一个项目可能依赖于具有封闭源代码许可证的jar,这会阻止其位于中央存储库中.有三种方法可以解决这种情况.

Since the dependency is described by Maven coordinates, you may be thinking: "This means that my project can only depend upon Maven artifacts!" The answer is, "Of course, but that's a good thing." This forces you to depend solely on dependencies that Maven can manage. There are times, unfortunately, when a project cannot be downloaded from the central Maven repository. For example, a project may depend upon a jar that has a closed-source license which prevents it from being in a central repository. There are three methods for dealing with this scenario.

  1. 使用安装插件在本地安装依赖项. 该方法是最简单的推荐方法.例如:

mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar

请注意,仍然需要一个地址,只有这次您使用命令行,安装插件才会使用给定的地址为您创建一个POM.

Notice that an address is still required, only this time you use the command line and the install plugin will create a POM for you with the given address.

...

  • systemPath :
    如果依赖项scopesystem,则仅使用.否则,如果设置了此元素,构建将失败. 路径必须是绝对的,因此建议使用属性指定计算机特定的路径(在下面的properties中有更多信息),例如${java.home}/lib.由于假定先安装了系统范围依赖项,所以Maven不会检查项目的存储库,而是检查以确保文件存在.否则,Maven将使构建失败,并建议您手动下载并安装.
  • systemPath:
    Is used only if the the dependency scope is system. Otherwise, the build will fail if this element is set. The path must be absolute, so it is recommended to use a property to specify the machine-specific path (more on properties below), such as ${java.home}/lib. Since it is assumed that system scope dependencies are installed a priori, Maven will not check the repositories for the project, but instead checks to ensure that the file exists. If not, Maven will fail the build and suggest that you download and install it manually.

[由我来强调.]

这篇关于Maven调试显示警告和错误,但最终会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆