Svn

建構maven項目時出現依賴錯誤

  • March 11, 2015

我正在嘗試將應用程序從在 Windows Eclipse 安裝上本地建構到 Jenkins 伺服器。從我所看到的設置是正確的,依賴關係應該解決。當我檢查 ~/.m2/repositories/ 文件夾時,即使是它抱怨的那些也在那裡。我不確定我在這裡做錯了什麼。我對 Jenkins 完全陌生,對 Maven 本身幾乎沒有經驗。

這是我的 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/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.my.project</groupId>
   <artifactId>My-Project</artifactId>
   <name>MyProject</name>
   <packaging>war</packaging>
   <version>1.0</version>
   <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <dependencies>
       <!-- Spring -->

       <!-- AspectJ -->

       <!-- Logging -->
       <dependency>
           <groupId>log4j</groupId>
           <artifactId>log4j</artifactId>
           <version>1.2.17</version>
           <exclusions>
               <exclusion>
                   <groupId>javax.mail</groupId>
                   <artifactId>mail</artifactId>
               </exclusion>
               <exclusion>
                   <groupId>javax.jms</groupId>
                   <artifactId>jms</artifactId>
               </exclusion>
               <exclusion>
                   <groupId>com.sun.jdmk</groupId>
                   <artifactId>jmxtools</artifactId>
               </exclusion>
               <exclusion>
                   <groupId>com.sun.jmx</groupId>
                   <artifactId>jmxri</artifactId>
               </exclusion>
           </exclusions>
           <scope>runtime</scope>
       </dependency>

       <!-- @Inject -->
       <dependency>
           <groupId>javax.inject</groupId>
           <artifactId>javax.inject</artifactId>
           <version>1</version>
       </dependency>

       <!-- Servlet -->
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>servlet-api</artifactId>
           <version>2.5</version>
           <scope>provided</scope>
       </dependency>
       <dependency>
           <groupId>javax.servlet.jsp</groupId>
           <artifactId>jsp-api</artifactId>
           <version>2.1</version>
           <scope>provided</scope>
       </dependency>
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>jstl</artifactId>
           <version>1.2</version>
       </dependency>

       <!-- Test -->
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>4.7</version>
           <scope>test</scope>
       </dependency>


       <!-- CUSTOM -->
       <dependency>
           <groupId>commons-io</groupId>
           <artifactId>commons-io</artifactId>
           <version>2.4</version>
       </dependency>
       <dependency>
           <groupId>org.apache.commons</groupId>
           <artifactId>commons-lang3</artifactId>
           <version>3.3.2</version>
       </dependency>
       <dependency>
           <groupId>commons-discovery</groupId>
           <artifactId>commons-discovery</artifactId>
           <version>0.5</version>
       </dependency>
       <dependency>
           <groupId>org.apache.axis</groupId>
           <artifactId>axis</artifactId>
           <version>1.4</version>
       </dependency>
       <dependency>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging</artifactId>
           <version>1.1.1</version>
       </dependency>
       <dependency>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging-adapters</artifactId>
           <version>1.1</version>
       </dependency>
       <dependency>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging-api</artifactId>
           <version>1.1</version>
       </dependency>
       <dependency>
           <groupId>commons-validator</groupId>
           <artifactId>commons-validator</artifactId>
           <version>1.3.1</version>
       </dependency>
       <dependency>
           <groupId>dom4j</groupId>
           <artifactId>dom4j</artifactId>
           <version>1.6.1</version>
       </dependency>
       <dependency>
           <groupId>org.jdom</groupId>
           <artifactId>jdom2</artifactId>
           <version>2.0.5</version>
       </dependency>
       <dependency>
           <groupId>jstl</groupId>
           <artifactId>jstl</artifactId>
           <version>1.2</version>
       </dependency>
       <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>slf4j-log4j12</artifactId>
           <version>1.7.7</version>
       </dependency>
       <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>jcl-over-slf4j</artifactId>
           <version>1.7.7</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-aop</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-aspects</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-beans</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-context</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-context-support</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-core</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-expression</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-jdbc</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-jms</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-orm</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-oxm</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-test</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-tx</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-web</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-webmvc</artifactId>
           <version>3.2.10.RELEASE</version>
       </dependency>
       <dependency>
           <groupId>org.postgresql</groupId>
           <artifactId>postgresql</artifactId>
           <version>9.3-1102-jdbc41</version>
       </dependency>
       <dependency>
           <groupId>net.sf.ehcache</groupId>
           <artifactId>ehcache</artifactId>
           <version>2.8.3</version>
       </dependency>
       <dependency>
           <groupId>commons-codec</groupId>
           <artifactId>commons-codec</artifactId>
           <version>1.9</version>
       </dependency>
       <dependency>
           <groupId>javax.validation</groupId>
           <artifactId>validation-api</artifactId>
           <version>1.1.0.Final</version>
       </dependency>
       <dependency>
           <groupId>org.jboss.logging</groupId>
           <artifactId>jboss-logging</artifactId>
           <version>3.1.4.GA</version>
       </dependency>
       <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-validator</artifactId>
           <version>4.3.2.Final</version>
       </dependency>
       <dependency>
           <groupId>commons-fileupload</groupId>
           <artifactId>commons-fileupload</artifactId>
           <version>1.3.1</version>
       </dependency>
       <dependency>
           <groupId>org.eclipse.birt.runtime</groupId>
           <artifactId>org.eclipse.birt.runtime</artifactId>
           <version>4.4.0</version>
       </dependency>
       <dependency>
           <groupId>org.eclipse.birt.runtime</groupId>
           <artifactId>viewservlets</artifactId>
           <version>4.3.1</version>
       </dependency>
       <dependency>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-war-plugin</artifactId>
           <version>2.5</version>
           <exclusions>
               <exclusion>
                   <groupId>org.slf4j</groupId>
                   <artifactId>slf4j-jdk14</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
       <dependency>
           <groupId>org.apache.httpcomponents</groupId>
           <artifactId>httpclient</artifactId>
           <version>4.3.6</version>
       </dependency>
       <dependency>
           <groupId>org.apache.xmlrpc</groupId>
           <artifactId>xmlrpc-common</artifactId>
           <version>3.1.3</version>
       </dependency>
       <dependency>
           <groupId>org.apache.xmlrpc</groupId>
           <artifactId>xmlrpc-client</artifactId>
           <version>3.1.3</version>
       </dependency>

   </dependencies>
   <scm>
       <connection>scm:svn:http://192.168.1.88:18080/svn/project</connection>
       <tag>HEAD</tag>
       <url>scm:svn:http://192.168.1.88:18080/svn/project</url>
   </scm>
   <build>
       <pluginManagement>
           <plugins>
               <plugin>
                   <groupId>org.eclipse.m2e</groupId>
                   <artifactId>lifecycle-mapping</artifactId>
                   <version>1.0.0</version>
                   <configuration>
                       <lifecycleMappingMetadata>
                           <pluginExecutions>
                               <pluginExecution>
                                   <pluginExecutionFilter>
                                       <groupId>org.codehaus.mojo</groupId>
                                       <artifactId>buildnumber-maven-plugin</artifactId>
                                       <versionRange>[1.0,)</versionRange>
                                       <goals>
                                           <goal>create</goal>
                                       </goals>
                                   </pluginExecutionFilter>
                                   <action>
                                       <execute>
                                           <runOnIncremental>true</runOnIncremental>
                                       </execute>
                                   </action>
                               </pluginExecution>
                           </pluginExecutions>
                       </lifecycleMappingMetadata>
                   </configuration>
               </plugin>
           </plugins>
       </pluginManagement>
       <plugins>
           <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>buildnumber-maven-plugin</artifactId>
               <version>1.0</version>
               <executions>
                   <execution>
                       <phase>validate</phase>
                       <goals>
                           <goal>create</goal>
                       </goals>
                   </execution>
               </executions>
               <configuration>
                   <doCheck>false</doCheck>
                   <doUpdate>false</doUpdate>
                   <timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
                   <revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
                   <providerImplementations>
                       <svn>javasvn</svn>
                   </providerImplementations>
               </configuration>
               <dependencies>
                   <dependency>
                       <groupId>com.google.code.maven-scm-provider-svnjava</groupId>
                       <artifactId>maven-scm-provider-svnjava</artifactId>
                       <version>2.0.2</version>
                   </dependency>
                   <dependency>
                       <groupId>org.tmatesoft.svnkit</groupId>
                       <artifactId>svnkit</artifactId>
                       <version>1.8.5</version>
                   </dependency>
               </dependencies>
           </plugin>
           <plugin>
               <artifactId>maven-eclipse-plugin</artifactId>
               <version>2.9</version>
               <configuration>
                   <additionalProjectnatures>
                       <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                   </additionalProjectnatures>
                   <additionalBuildcommands>
                       <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                   </additionalBuildcommands>
                   <downloadSources>true</downloadSources>
                   <downloadJavadocs>true</downloadJavadocs>
               </configuration>
           </plugin>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>2.5.1</version>
               <configuration>
                   <source>1.7</source>
                   <target>1.7</target>
                   <compilerArgument>-Xlint:all</compilerArgument>
                   <showWarnings>true</showWarnings>
                   <showDeprecation>true</showDeprecation>
               </configuration>
           </plugin>
           <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>exec-maven-plugin</artifactId>
               <version>1.2.1</version>
               <configuration>
                   <mainClass>org.test.int1.Main</mainClass>
               </configuration>
           </plugin>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-war-plugin</artifactId>
               <version>2.5</version>
               <configuration>
                   <archive>
                       <manifest>
                           <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                       </manifest>
                       <manifestEntries>
                           <Implementation-Build>${buildNumber}</Implementation-Build>
                       </manifestEntries>
                   </archive>
               </configuration>
           </plugin>
       </plugins>
   </build>
</project>

以下是我嘗試從命令行清理項目時遇到的錯誤(當我嘗試在 Jenkins 中建構時,我得到了同樣的錯誤加上更多):

[root@localhost workspace]# /opt/apache-maven-3.2.5/bin/mvn clean install -U
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My-Project 1.0
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/commons-logging/commons-logging-adapters/1.1/commons-logging-adapters-1.1.pom
[WARNING] The POM for commons-logging:commons-logging-adapters:jar:1.1 is missing, no dependency information available
Downloading: https://repo.maven.apache.org/maven2/commons-discovery/axis/1.4/axis-1.4.pom
[WARNING] The POM for commons-discovery:axis:jar:1.4 is missing, no dependency information available
Downloading: https://repo.maven.apache.org/maven2/commons-discovery/axis/1.4/axis-1.4.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.228 s
[INFO] Finished at: 2015-02-10T16:01:34-05:00
[INFO] Final Memory: 16M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project My-Project: Could not resolve dependencies for project com.my.project:My-Project:war:1.0: Could not find artifact commons-discovery:axis:jar:1.4 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[root@localhost workspace]#

感謝您提供任何幫助,因為我已盡我所能搜尋網路。請記住,這個項目的建構沒有來自 Eclipse 的任何錯誤,所以這就是為什麼我認為這是 Linux 伺服器上的設置問題。

編輯:我什至嘗試移動/刪除整個 ~/.m2/repositories/ 文件夾並執行“mvn clean install -U”

所以我找到了解決這個問題的部分解決方案。我從命令行呼叫了 maven:

sudo -u jenkins /opt/apache-maven-3.2.5/bin/mvn archetype:generate -DgroupId=org.eclipse.m2e -DartifactId=lifecycle-mapping -Dversion=1.0.0 -DarchetypeArtifactId=maven-archetype-mojo

這解決了特定問題,但我遇到了其他問題。我會為此再發一篇文章。

在我看來,commons-discovery:axis:jar 要麼已被移動,要麼不是正確的 GAV。

我看到這個:

<dependency>
 <groupId>axis</groupId>
 <artifactId>axis</artifactId>
 <version>(PUT YOUR VERSION HERE)</version>
</dependency>

還有這個:

<dependency>
 <groupId>commons-discovery</groupId>
 <artifactId>commons-discovery</artifactId>
 <version>(PUT YOUR VERSION HERE)</version>
</dependency>

我看到的另一種情況是,您似乎在沒有代理的情況下直接訪問 repo1/maven Central。

我強烈建議設置這種東西以幫助防止工件移動時出現錯誤(重定向似乎並不總是有效,並且肯定不會永遠持續下去)。

引用自:https://serverfault.com/questions/666592