【问题标题】:Maven uses different dependencies depending on which machine it runs?Maven 根据运行的机器使用不同的依赖项?
【发布时间】:2014-10-26 16:03:07
【问题描述】:

我有一个正在本地机器上正确构建的项目。在我的公司,我们使用服务器机器进行持续集成,但该机器没有连接到互联网。所以我已经设置了工件并将我的整个存储库复制到它。然后将jenkins与这个神器连接起来。所以詹金斯应该毫无问题地进行构建,不是吗?因为它与我的本地项目具有相同的设置。

构建几秒钟后弹出一条消息说他找不到依赖项:

[错误] 无法在项目 crs-data 上执行目标:无法解析 com.ing.crs:crs-data:jar:1.1.3-SNAPSHOT 项目的依赖项: 未能收集依赖项 [com.ing.crs:crs-framework:jar:1.1.3-SNAPSHOT(编译), org.apache.openjpa:openjpa-all:jar:2.3.0(提供), ibm.websphere:j2ee6:jar:8.5.0(提供), ibm.websphere:jpaThinClient:jar:8.5.0(提供), com.google.guava:guava:jar:14.0.1(编译), org.hamcrest:hamcrest-all:jar:1.3 (测试), junit:junit:jar:4.11 (测试), mockito-all:mockito-all:jar:1.8.4(测试),oracle.jdbc:ojdbc6:jar:11.2 (测试), com.h2database:h2:jar:1.3.167 (测试), ibm.websphere:embeddedEJBContainer:jar:8.5.0(测试), com.ing.be:bbllib.DeploymentInfo:jar:2.3.2(提供)]:未能 读取 commons-dbcp:commons-dbcp:jar:1.4 的工件描述符:可以 不从/到转移工件 commons-dbcp:commons-dbcp:pom:1.4 crs.maven.repo (http://sdbeapp00433.devbe.development:8082/artifactory/repo): 访问 拒绝: http://sdbeapp00433.devbe.development:8082/artifactory/repo/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.pom -> [帮助 1]

但是在本地构建甚至不使用 commons-dbcp:commons-dbcp:pom:1.4。这怎么可能????

pom:

<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>
    <groupId>com.ing.crs</groupId>
    <artifactId>crs-parent-pom</artifactId>
    <version>1.1.3-SNAPSHOT</version>
    <relativePath>../crs-parent-pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>crs-data</artifactId>
<version>${project.crs-data.version}</version>

<profiles>
    <profile>
        <id>default</id>
        <properties>
            <dbDictionary>disableAlterSeqenceIncrementBy=true</dbDictionary>
        </properties>
    </profile>
    <profile>
        <id>stubs</id>
        <properties>
            <dbDictionary></dbDictionary>
        </properties>
    </profile>
</profiles>

<dependencies>
    <!-- CRS -->
    <dependency>
        <groupId>com.ing.crs</groupId>
        <artifactId>crs-framework</artifactId>
        <version>${project.crs-framework.version}</version>
    </dependency>

    <!-- Other -->
    <dependency>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa-all</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ibm.websphere</groupId>
        <artifactId>j2ee6</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ibm.websphere</groupId>
        <artifactId>jpaThinClient</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>

    <!-- test -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>mockito-all</groupId>
        <artifactId>mockito-all</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>oracle.jdbc</groupId>
        <artifactId>ojdbc6</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.167</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ibm.websphere</groupId>
        <artifactId>embeddedEJBContainer</artifactId>
        <version>8.5.0</version>
        <scope>test</scope>
    </dependency>           
    <dependency>
        <groupId>com.ing.be</groupId>
        <artifactId>bbllib.DeploymentInfo</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <finalName>crs-data</finalName>
    <outputDirectory>target/crs-data</outputDirectory>
    <plugins>          
        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>2.2.4</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <compilerArguments>-Aopenjpa.source=7 -Aopenjpa.metamodel=true</compilerArguments>
                        <processors>
                            <processor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</processor>
                        </processors>
                        <outputDirectory>target/generated-sources/metamodel</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>target/generated-sources/metamodel</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
        </plugin> 
        <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <version>2.3.0</version>
            <executions>
                <execution>
                    <id>enhancer_for_test</id>
                    <configuration>
                        <includes>**/entities/**/*.class</includes>
                        <includes>**/data/**/*.class</includes>
                        <addDefaultConstructor>true</addDefaultConstructor>
                        <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                    </configuration>
                    <phase>compile</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa</artifactId>
                    <version>2.3.0</version>
                </dependency>
            </dependencies>
        </plugin>                        
    </plugins>

    <pluginManagement>

        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <id>copy-test-persistence</id>
                        <phase>process-test-resources</phase>
                        <configuration>
                            <tasks>
                                <!--backup the "proper" persistence.xml-->
                                <copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper"/>
                                <!--replace the "proper" persistence.xml with the "test" version-->
                                <!-- copy file="${project.build.testOutputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml"/-->
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restore-persistence</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <tasks>
                                <!--restore the "proper" persistence.xml-->
                                <copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>           

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathLayoutType>custom</classpathLayoutType>
                            <customClasspathLayout>${artifact.artifactId}.${artifact.extension}</customClasspathLayout>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Version>${project.version}</Implementation-Version>
                            <Build-Time>${timestamp}</Build-Time>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
            only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.1.1</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.codehaus.mojo
                                    </groupId>
                                    <artifactId>
                                        openjpa-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.0,)
                                    </versionRange>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnIncremental>false</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.openjpa
                                    </groupId>
                                    <artifactId>
                                        openjpa-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.2.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <resources>
        <resource>
          <directory>src/main/resources/</directory>
          <filtering>true</filtering>
        </resource>
    </resources>
</build>

【问题讨论】:

  • 你能给我们一些关于这个的其他信息应该没有任何问题构建吗?你在构建什么(除了分享你的 pom.xml)?
  • commons-dbcp 可由您的依赖项/插件之一使用。将您的 ~/.m2 复制到 ~/jenkins/.m2 并重试。第二种解决方案是在 artifactory 中配置代理和外部存储库。
  • 问题出在这个:Access denied to: http://sdbeapp00433.devbe.development:8082/artifactory/repo/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.pom ...

标签: maven jenkins dependencies artifactory building


【解决方案1】:

由于身份验证问题,Maven 无法从 Artifactory 下载依赖项,因此您的构建失败:

Access denied to: http://sdbeapp00433.devbe.development:8082/artifactory/repo/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.pom

如果您查看 Artifactory access.log,您应该会看到有关被拒绝下载的匹配日志条目。

如果您正在使用 Artifactory Jenkins 插件,则可以按照here 的说明配置解析器凭据。
如果您不使用 Artifactory Jenkins 插件,则应按照"Working With Maven" 中的说明配置 Maven 身份验证。这需要将正确的凭据添加到 Maven settings.xml 文件。
第三种选择是允许匿名访问 Artifactory,如 here 所述。这将允许在无需身份验证的情况下从 Artifactory 解析依赖项。

commons-dbcp 可能是一个传递依赖。如果你想找到它的来源,你应该使用 Maven 依赖插件的dependency:tree 目标,它显示了这个项目的依赖树。

附带说明,您不应使用“repo”存储库。这是一个默认的全局虚拟存储库,它有效地聚合了所有其他存储库。通过使用此 URL 配置 Maven,对工件的任何请求都将通过 Artifactory,Artifactory 将搜索系统中定义的所有本地和远程存储库。最好使用一个虚拟存储库,它只为您的构建聚合相关的存储库。

【讨论】:

  • Artifactory 没有身份验证错误。它说这是因为它找不到它试图打开的 pom。但问题是为什么在我本地构建时不使用该文件时它需要该文件。因此,当我在本地构建与通过 jenkins 构建时,构建行为会有所不同。
  • 尝试使用 dependency:tree 来查找 commons-dbcp 依赖的来源。 Jenkins 中的构建环境与您的本地环境之间是否存在任何差异:Maven 版本,正在使用的 Maven 配置文件?您是否尝试使用干净的 Maven 缓存(本地存储库)在本地构建?另外,你有没有尝试从 Artifactory 下载 commons-dbcp 依赖?
猜你喜欢
  • 2013-11-17
  • 2020-10-30
  • 1970-01-01
  • 2016-03-08
  • 1970-01-01
  • 2020-02-03
  • 1970-01-01
  • 2019-12-15
  • 1970-01-01
相关资源
最近更新 更多