2013-03-08 216 views
0

我正在嘗試將pom.xml配置重寫爲gradle腳本。關於POM依賴的部分看起來像這樣:從maven遷移到gradle:「gradle build」WAR構建任務失敗

<dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${org.springframework-version}</version> 
     <exclusions> 
      <!-- Exclude Commons Logging in favor of SLF4j --> 
      <exclusion> 
       <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-aop</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 

    <!-- Spring security -->  
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>${spring.security.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-ldap</artifactId> 
     <version>${spring.security.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>${spring.security.version}</version> 
    </dependency> 
    <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>${spring.security.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-taglibs</artifactId> 
     <version>${spring.security.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-acl</artifactId> 
     <version>${spring.security.version}</version> 
    </dependency> 

    <!-- Tiles dependancies --> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-api</artifactId> 
     <version>2.1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-core</artifactId> 
     <version>2.1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-jsp</artifactId> 
     <version>2.1.4</version> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-servlet</artifactId> 
     <version>2.1.4</version> 
    </dependency> 

    <!-- AspectJ --> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>${org.aspectj-version}</version> 
    </dependency> 

    <!-- MySQL database driver --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.19</version> 
    </dependency> 

    <!-- PostgreSQL database driver --> 
    <dependency> 
     <groupId>postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.1-901.jdbc4</version> 
    </dependency> 

    <!-- Required by databases --> 
    <dependency> 
     <groupId>org.apache.derby</groupId> 
     <artifactId>derbyclient</artifactId> 
     <version>10.9.1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-jdbc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 

    <!-- Logging --> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${org.slf4j-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>jcl-over-slf4j</artifactId> 
     <version>${org.slf4j-version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>${org.slf4j-version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.15</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> 

    <!-- Validation --> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
    </dependency> 

    <!-- Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.1.7.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>4.3.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate.javax.persistence</groupId> 
     <artifactId>hibernate-jpa-2.0-api</artifactId> 
     <version>1.0.1.Final</version> 
    </dependency> 

    <!-- DOM4j --> 
    <dependency> 
     <groupId>dom4j</groupId> 
     <artifactId>dom4j</artifactId> 
     <version>1.6.1</version> 
    </dependency> 

    <!-- Commons -->   
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>1.8.3</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.2.1</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-digester</groupId> 
     <artifactId>commons-digester</artifactId> 
     <version>2.1</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-fileupload</groupId> 
     <artifactId>commons-fileupload</artifactId> 
     <version>1.2.2</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.3</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.6</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.1</version> 
    </dependency> 

    <!-- Language recognizer required by Spring --> 
    <dependency> 
     <groupId>antlr</groupId> 
     <artifactId>antlr</artifactId> 
     <version>2.7.7</version> 
    </dependency> 

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

目前負責依賴gradle這個腳本的部分看起來像這樣:

//---------------------------------------------------------------------------- 
//     SERVER'S DEPENDENCIES' CONFIGURATION 
//---------------------------------------------------------------------------- 

configure(serverProjects) { 
    repositories { 
     mavenCentral() 
     maven { url 'http://repository.jboss.org/nexus/content/groups/public' } 
    } 
} 

// Spring Framework: 
def springVersion = '3.1.0.RELEASE' 
def springContext = "org.springframework:spring-context:${springVersion}" 
def springMVC  = "org.springframework:spring-webmvc:${springVersion}" 
def springAOP  = "org.springframework:spring-aop:${springVersion}" 
def springORM  = "org.springframework:spring-orm:${springVersion}" 
def springJDBC = "org.springframework:spring-jdbc:${springVersion}" 


// Spring Security: 
def springSecurityVersion = '3.1.2.RELEASE' 
def springSecurityCore = "org.springframework.security:spring-security-core:${springSecurityVersion}" 
def springSecurityLDAP = "org.springframework.security:spring-security-ldap:${springSecurityVersion}" 
def springSecurityConfig = "org.springframework.security:spring-security-config:${springSecurityVersion}" 
def springSecurityWeb  = "org.springframework.security:spring-security-web:${springSecurityVersion}" 
def springSecurityTaglibs = "org.springframework.security:spring-security-taglibs:${springSecurityVersion}" 
def springSecurityACL  = "org.springframework.security:spring-security-acl:${springSecurityVersion}" 


// Tiles: 
def tilesVersion = '2.1.4' 
def tilesCore = "org.apache.tiles:tiles-core:${tilesVersion}" 
def tilesAPI  = "org.apache.tiles:tiles-api:${tilesVersion}" 
def tilesJSP  = "org.apache.tiles:tiles-jsp:${tilesVersion}" 


// AspectJ: 
def aspectJVersion = '1.6.9' 
def aspectJ  = "org.aspectj:aspectjrt:${aspectJVersion}" 


// Databases: 
def apacheDerbyVersion = '10.9.1.0' 
def apacheDerby  = "org.apache.derby:derbyclient:${apacheDerbyVersion}" 

def mySQLVersion = '5.1.19' 
def mySQL  = "mysql:mysql-connector-java:${mySQLVersion}" 

def postgreSQLVersion = '9.1-901.jdbc4' 
def postgreSQL  = "postgresql:postgresql:${postgreSQLVersion}" 


// Logging: 
def slf4jVersion = '1.5.10' 
def slf4jAPI  = "org.slf4j:slf4j-api:${slf4jVersion}" 
def slf4jJCL  = "org.slf4j:jcl-over-slf4j:${slf4jVersion}" 
def slf4jLog4J = "org.slf4j:slf4j-log4j12:${slf4jVersion}" 

def log4JVersion = '1.2.15' 
def log4J  = "log4j:log4j:${log4JVersion}" 

// Javax: 
def javaxServletAPIVersion = '2.5' 
def javaxServletAPI  = "javax.servlet:servlet-api:${javaxServletAPIVersion}" 

def javaxJspApiVersion  = '2.1' 
def javaxJspApi   = "javax.servlet.jsp:jsp-api:${javaxJspApiVersion}" 

def javaxJSTLVersion  = '1.2' 
def javaxJSTL    = "javax.servlet:jstl:${javaxJSTLVersion}" 

def javaxInjectVersion  = '1' 
def javaxInject   = "javax.inject:javax.inject:${javaxInjectVersion}" 

def javaxValidationVersion = '1.0.0.GA' 
def javaxValidation  = "javax.validation:validation-api:${javaxValidationVersion}" 


// Hibernate: 
def hibernateCoreVersion  = '4.1.7.Final' 
def hibernateCore    = "org.hibernate:hibernate-core:${hibernateCoreVersion}" 

def hibernateValidatorVersion = '4.3.0.Final' 
def hibernateValidator  = "org.hibernate:hibernate-validator:${hibernateValidatorVersion}" 

def hibernateJPAVersion  = '1.0.1.Final' 
def hibernateJPA    = "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:${hibernateJPAVersion}" 


// dom4j: 
def dom4JVersion = '1.6.1' 
def dom4J  = "dom4j:dom4j:${dom4JVersion}" 


// antlr: 
def antlrVersion = '2.7.7' 
def antlr  = "antlr:antlr:${antlrVersion}" 


// commons: 
def commonsBeanUtilsVersion = '1.8.3' 
def commonsBeanUtils   = "commons-beanutils:commons-beanutils:${commonsBeanUtilsVersion}" 

def commonsCollectionsVersion = '3.2.1' 
def commonsCollections  = "commons-collections:commons-collections:${commonsCollectionsVersion}" 

def commonsDigesterVersion = '2.1' 
def commonsDigester   = "commons-digester:commons-digester:${commonsDigesterVersion}" 

def commonsFileUploadVersion = '1.2.2' 
def commonsFileUpload   = "commons-fileupload:commons-fileupload:${commonsFileUploadVersion}" 

def commonsIOVersion   = '2.3' 
def commonsIO     = "commons-io:commons-io:${commonsIOVersion}" 

def commonsLangVersion  = '2.6' 
def commonsLang    = "commons-lang:commons-lang:${commonsLangVersion}" 

def commonsLoggingVersion  = '1.1.1' 
def commonsLogging   = "commons-logging:commons-logging:${commonsLoggingVersion}" 


// JUnit4: 
def jUnitVersion = '4.7' 
def jUnit  = "junit:junit:${jUnitVersion}" 

project(':WARProject') { 
    dependencies { 
     // Spring Framework: 
     compile(springContext) { 
      exclude group: 'commons-logging', module: 'commons-logging' 
     } 
     compile(
      springMVC, springAOP, springORM,  springJDBC 
     ) 

     // Spring Security: 
     compile(
      springSecurityCore, springSecurityLDAP,  springSecurityConfig, 
      springSecurityWeb, springSecurityTaglibs, springSecurityACL 
     ) 

     // Tiles: 
     compile(
      tilesCore, tilesAPI, tilesJSP 
     ) 

     // AspectJ: 
     compile(aspectJ) 

     // Databases: 
     compile(
      apacheDerby, mySQL, postgreSQL 
     ) 

     // Logging: 
     compile(slf4jAPI) 
     runtime(
      slf4jJCL, slf4jLog4J 
     ) 
     runtime(log4J) { 
      exclude group: 'javax.mail', module: 'mail' 
      exclude group: 'javax.jms', module: 'jms' 
      exclude group: 'com.sun.jdmk', module: 'jmxtools' 
      exclude group: 'com.sun.jmx', module: 'jmxri' 
     } 

     // Javax: 
     compile(
      javaxInject,  javaxValidation,  javaxJSTL 
     ) 
     providedCompile(
      javaxServletAPI, javaxJspApi 
     ) 

     // Hibernate: 
     compile(
      hibernateCore, hibernateValidator, hibernateJPA 
     ) 

     // dom4j: 
     compile(dom4J) 

     // antlr: 
     compile(antlr) 

     // commons: 
     compile(
      commonsBeanUtils, commonsCollections, commonsDigester, 
      commonsFileUpload, commonsIO,   commonsLang, 
      commonsLogging 
     ) 

     // JUnit: 
     testCompile(
      jUnit 
     ) 
    } 
} 

當我嘗試建立WAR文件,我收到信息org.apache.log4j.Logger包不存在。如果我將runtime替換爲compile,我會收到錯誤Artifact 'javax.jms:jms:[email protected]' not found,好像exclude子句完全被忽略。

providedRuntimeprovidedCompile具有分別與runtimecompile相同的結果。

我該如何修改腳本來成功創建WAR文件?

編輯:所示

gradle :WARProject:dependencies

... 
+--- org.slf4j:slf4j-log4j12:1.5.10 [default] 
| +--- org.slf4j:slf4j-api:1.5.10 [compile,runtime,master] (*) 
| \--- log4j:log4j:1.2.15 [compile,runtime,master] 
|   +--- javax.mail:mail:1.4 [compile,master,runtime] 
|   | \--- javax.activation:activation:1.1 [compile,master,runtime] 
|   +--- javax.jms:jms:1.1 [compile,master,runtime] 
|   +--- com.sun.jdmk:jmxtools:1.2.1 [compile,master,runtime] 
|   \--- com.sun.jmx:jmxri:1.2.1 [compile,master,runtime] 

這意味着gradle這個不排除那些依賴關係(它是唯一的,地方的javax.jms:JMS發生)。我嘗試在定義的末尾添加@jar,並在排除區塊中添加transitive = false - 沒有結果。我還應該嘗試什麼?

回答

5

實際上,版本1.2.15的log4j缺少Maven的許可問題依賴關係。並建議使用log4j的1.2.16版本。

嘗試:

def log4JVersion = '1.2.15' 
def log4J  = "log4j:log4j:${log4JVersion}" 

=>

def log4JVersion = '1.2.16' 
def log4J  = "log4j:log4j:${log4JVersion}" 

,或者可以排除JMX和JDMK,如果你不需要他們在gradle這個文件。我看到你在pom中排除它們,但是,在gradle文件中排除了聲明。

試試補充一點:

configurations { 
    all*.exclude group: 'javax.jms', module: 'jms' 
    all*.exclude group: 'com.sun.jdmk', module: 'jmxtools' 
    all*.exclude group: 'com.sun.jmx', module: 'jmxri' 
    published 
} 

乾杯!

+0

謝謝!我去了第一個解決方案。老實說,我從來沒有猜到,原因是什麼。 – 2013-03-10 13:09:51

相關問題