【问题标题】:Maven try to download a <packaing>pom</package> pom as a jar file and cannot find itMaven 尝试将 <packaging>pom</packaging> pom 下载为 jar 文件但找不到
【发布时间】:2017-07-21 01:58:37
【问题描述】:

我的 maven pom.xml 非常简单:

<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>
  <groupId>org.acb</groupId>
  <artifactId>adfafa</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
<dependency>
  <!-- https://mvnrepository.com/artifact/org.pentaho/pentaho-aggdesigner -->
<groupId>org.pentaho</groupId>
<artifactId>pentaho-aggdesigner</artifactId>
    <version>5.1.5-jhyde</version>
</dependency>

  </dependencies>
</project>

从 pom.xml 中,我只想要 pentaho-aggdesigner 这是两个模块 pentaho-aggdesigner-core.jar 和 pentaho-aggdesigner-algorithm.jar 的父 pom,我的远程仓库是:http://repo.spring.io/plugins-release

所以,我想,maven会访问http://repo.spring.io/plugins-release/org/pentaho/pentaho-aggdesigner/5.1.5-jhyde/pentaho-aggdesigner-5.1.5-jhyde.pom下载父pom,然后根据pom,它会下载两个子模块pentaho-aggdesigner-core.jar和pentaho-aggdesigner-algorithm.jar。 pentaho-aggdesigner-5.1.5-jhyde.pom的内容是:

<?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>

  <groupId>org.pentaho</groupId>
  <artifactId>pentaho-aggdesigner</artifactId>
  <packaging>pom</packaging>
  <version>5.1.5-jhyde</version>
  <name>Pentaho Aggregate Designer</name>
  <description>Designs aggregate tables for the Mondrian OLAP engine</description>
  <url>http://github.com/pentaho/mondrian</url>
  <inceptionYear>2006</inceptionYear>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <distributionManagement>
    <repository>
      <id>conjars</id>
      <name>Conjars</name>
      <url>http://conjars.org/repo</url>
      <layout>default</layout>
    </repository>
  </distributionManagement>



  <issueManagement />

  <scm>
    <connection>scm:git:git://github.com/julianhyde/pentaho-aggdesigner.git</connection>
    <developerConnection>scm:git:git@github.com:julianhyde/pentaho-aggdesigner.git</developerConnection>
    <url>http://github.com/julianhyde/pentaho-aggdesigner/tree/master</url>
    <tag>pentaho-aggdesigner-5.1.5-jhyde</tag>
  </scm>

  <modules>
    <module>pentaho-aggdesigner-algorithm</module>
    <module>pentaho-aggdesigner-core</module>
  </modules>

  <dependencyManagement>
    <!-- Dependency versions for all sub-modules.
         Sorted by groupId, artifactId. -->
    <dependencies>
      <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.4</version>
      </dependency>
      <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
      </dependency>
      <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.1</version>
      </dependency>
      <dependency>
        <groupId>org.pentaho</groupId>
        <artifactId>pentaho-aggdesigner-algorithm</artifactId>
        <version>5.1.5-jhyde</version>
      </dependency>
      <dependency>
        <groupId>pentaho</groupId>
        <artifactId>mondrian</artifactId>
        <version>3.6.9</version>
      </dependency>
      <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>jaxen</groupId>
        <artifactId>jaxen</artifactId>
        <version>1.1-beta-6</version>
      </dependency>

      <!-- Test dependencies. -->
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.jmock</groupId>
        <artifactId>jmock-junit4</artifactId>
        <version>2.4.0</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.jmock</groupId>
        <artifactId>jmock-legacy</artifactId>
        <version>2.4.0</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.pentaho</groupId>
        <artifactId>pentaho-aggdesigner-algorithm</artifactId>
        <version>5.1.5-jhyde</version>
        <type>test-jar</type>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.1</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.17</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>pentaho</groupId>
        <artifactId>mondrian-data-foodmart-hsqldb</artifactId>
        <version>0.2</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9.1</version>
        <configuration>
          <links>
            <link>http://docs.oracle.com/javase/7/docs/api/</link>
          </links>
        </configuration>
      </plugin>
    </plugins>
  </reporting>

  <build>
    <defaultGoal>package</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.8</version>
        <executions>
          <execution>
            <id>properties</id>
            <goals>
              <goal>properties</goal>
            </goals>
            <phase>initialize</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>verify</phase>
            <goals>
              <goal>jar-no-fork</goal>
              <goal>test-jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>build.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- If we don't specify gitexe version, git doesn't
             commit during release process. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.scm</groupId>
            <artifactId>maven-scm-provider-gitexe</artifactId>
            <version>1.9.1</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
      </plugin>
    </plugins>
  </build>
</project>

可以看到,pom明确表示我不是jar pom,而是package pom。但是maven还是认为是jar pom,尝试从远程repo下载pentaho-aggdesigner.jar,当然jar文件不存在抛出这个错误:

[ERROR] Failed to execute goal on project adfafa: Could not resolve dependencies for project org.acb:adfafa:jar:0.0.1-SNAPSHOT: Could not find artifact org.pentaho:pentaho-aggdesigner:jar:5.1.5-jhyde in springmaven (http://repo.spring.io/plugins-release/) -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project adfafa: 
Could not resolve dependencies for project org.acb:adfafa:jar:0.0.1-SNAPSHOT: Could not find artifact org.pentaho:pentaho-aggdesigner:jar:5.1.5-jhyde in springmaven (http://repo.spring.io/plugins-release/)

【问题讨论】:

    标签: maven pom.xml packaging parent-pom


    【解决方案1】:

    不,maven 不是那样工作的。另见How to use POMs as a dependency in Maven?

    父模块只是为它的子模块组合配置的一个技巧。它不会自动引入传递依赖。

    因此您需要指定确切的 jar 依赖项。大概是这样的:

    <dependency>
        <groupId>org.pentaho</groupId>
        <artifactId>pentaho-aggdesigner-algorithm</artifactId>
        <version>5.1.5-jhyde</version>
    </dependency>
    <dependency>
        <groupId>org.pentaho</groupId>
        <artifactId>pentaho-aggdesigner-core</artifactId>
        <version>5.1.5-jhyde</version>
    </dependency>
    

    通过在依赖项中包含类型“pom”,您可以像这样使用 pom:

    <dependency>
      <groupId>xxx.yyy</groupId>
      <artifactId>pentaho-all</artifactId>
      <type>pom</type>
      <version>XXXX</version>
    </dependency>
    

    在这种情况下,pentaho-all 将是一个带有直接依赖项列表的 pom,然后您可以将其作为传递依赖项导入。但是你找到的聚合器pom没有直接依赖,只有模块和依赖管理,这样就不行了。

    【讨论】:

    • 这是我从src代码编译hive时遇到的。编译失败,我找到了配置。所以,很奇怪。
    • 你的意思是,这显然是一个错误的配置?但是 pom 而不是 jar 表示什么?
    • 包装“pom”意味着模块本身不会创建jar/war/ear。它主要用于父 pom 或带有子模块的 pom。
    【解决方案2】:

    我在 pentaho-aggdesigner:pom:5.1.5-jhyde 上遇到了同样的问题,这个网站解决了我的问题

    https://www.programmersought.com/article/76106349302/

    基本上,在maven settings.xml中使用aliyun作为镜像。对于这种情况,不要使用 repo.spring.io 作为镜像,因为它需要登录并且会出现“身份验证”错误。

    【讨论】:

      【解决方案3】:

      将以下依赖项添加到 pom.xml 将有所帮助

      <!-- https://mvnrepository.com/artifact/org.pentaho/pentaho-aggdesigner-algorithm -->
      <dependency>
          <groupId>org.pentaho</groupId>
          <artifactId>pentaho-aggdesigner-algorithm</artifactId>
          <version>5.1.5-jhyde</version>
          <scope>test</scope>
      </dependency>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-09
        • 1970-01-01
        • 1970-01-01
        • 2017-02-23
        • 2012-02-05
        • 2019-01-13
        • 1970-01-01
        • 2011-12-06
        相关资源
        最近更新 更多