2013-05-08 37 views
2

請幫助我解決一些編譯錯誤,因爲Grails沒有從基於pom.xml文件的Maven倉庫中挑選罐子。Grails沒有從基於pom.xml的maven倉庫中挑選罐子

我BuildConfig.groovy這樣

grails.project.dependency.resolution = { 
    // inherit Grails' default dependencies 
    inherits("global") { 
     // uncomment to disable ehcache 
     // excludes 'ehcache' 
     //excludes "grails-plugin-log4j" 
    } 

    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose' 
    checksums true // Whether to verify checksums on resolve 
    //excludes "grails-plugin-log4j" 
    pom true 
    repositories { 
     inherits true // Whether to inherit repository definitions from plugins 
     //grailsPlugins() 
     /// grailsHome() 
     // grailsCentral() 

     mavenCentral() 
     mavenLocal() 

     // These are for the hudson machine 
     // mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo" 
     // mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo" 

     //mavenRepo "http://snapshots.repository.codehaus.org" 
     //mavenRepo "http://repository.codehaus.org" 
     // mavenRepo "http://download.java.net/maven/2/" 
     //mavenRepo "http://repository.jboss.com/maven2/" 
    } 

    dependencies { 
     // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg. 
     runtime 'mysql:mysql-connector-java:5.1.5' 
       compile 'org.apache.activemq:activemq-core:5.3.0' 
     test 'org.objenesis:objenesis:1.2' 
     compile 'org.slf4j:slf4j-log4j12:1.6.6' 
     //compile "spring-security-config:3.0.1.RELEASE" 
    } 

    plugins { 
     compile ":spring-security-core:1.2.7.3" 
     compile ":spring-security-ui:0.2" 
     compile ":jquery-ui:1.8.15" 
     compile ":jqgrid:3.8.0.1" 
     compile ":famfamfam:1.0.1" 
     compile ":mail:1.0" 
     compile ":jms:1.2" 
     compile ":calendar:1.2.1" 
     compile ':gpars:0.3' 
     compile ":lang-selector:0.3" 
     compile ":crypto:2.0" 
     compile ":grails-melody:1.13" 
     runtime ":hibernate:$grailsVersion" 
     runtime ":jquery:1.7.1" 
     //runtime ":resources:1.1.6" 
     runtime ":resources:1.2.RC2" 
     runtime ":export:1.5" 

     // Uncomment these (or add new ones) to enable additional resources capabilities 
     //runtime ":zipped-resources:1.0" 
     //runtime ":cached-resources:1.0" 
     //runtime ":yui-minify-resources:0.1.4" 
     build ":tomcat:$grailsVersion" 
     test ":spock:0.6" 
    } 
} 

我得到錯誤:

Configuring classpath. 
| Environment set to development..... 
| Packaging Grails application..... 
| Compiling 141 source files. 
| Error Compilation error: startup failed: 
/mycompany/dev/rmaddidev/wsmavenTest/pro/src/groovy/com/mycompany/rms/common/RMSExportService.groovy: 15: unable to resolve class org.xhtmlrenderer.pdf.ITextRenderer 
@ line 15, column 1. 
    import org.xhtmlrenderer.pdf.ITextRenderer 
^
1 error 

ITextRenderer類核心renderer.jar我在Maven POM文件規定如下存在。

如果我在BuildConfig.groovy中添加這些罐子,那麼它工作正常。

compile 'org.xhtmlrenderer:core-renderer:R8' 
    compile 'com.lowagie:itext:2.0.8' 

和我的POM文件:

<dependencies> 
<dependency> 
    <groupId>org.xhtmlrenderer</groupId> 
    <artifactId>core-renderer</artifactId> 
    <version>R8</version> 
</dependency> 
<dependency> 
    <groupId>com.lowagie</groupId> 
    <artifactId>itext</artifactId> 
    <version>2.0.8</version> 
</dependency> 
+0

你試圖使用哪個命令? 'mvn install'或'grails run-app'或'mvn grails:run-app'? – dmahapatro 2013-05-08 05:13:37

回答

3

更新正確性和細節

您仍然可以使用標準的Grails只要你所有的依賴性在BuildConfig引用命令.groovy

但是,您可能不想同時維護Maven POM和BuildConfig.groovy,除非您有一些團隊成員不想使用Maven。

除非項目需要使用Maven和標準Grails命令行構建,否則不惜一切代價避免BuildConfig.groovy以及Grails命令行。


當使用Maven,你需要做到以下幾點:

  • 不要設置的依賴關係BuildConfig.groovy,將它們添加到您的POM:

    • 的依賴從您的BuildConfig.groovy塊移動到POM(默認隱含類型標籤設置爲jar)。
    • 對於非依賴的JAR(插件或者非二進制插件),則需要依賴明確設置爲拉鍊在你的pom.xml。
  • 此外,從您的BuildConfig.groovy和set the repositories in your POM刪除存儲庫塊。

  • 不要使用grails命令行,使用Grails Maven目標,就像@dmahapatro所暗示的那樣。


當您決定使用Maven和Grails,它意味着你想避免在您的BuildConfig.groovy設置。

然後,您將擁有由Maven POM驅動的構建設置(如果100%可能)。

+0

同意。小的更正建議。當在'BuildConfig'中指定'pom true'時,你仍然可以使用'grails run-app',並且是的,所有'dependencies'都應該在'pom'中提到,而不是'BuildConfig'。 +1 – dmahapatro 2013-05-08 06:22:26

+0

是的,dmahapatro,我只是不想鼓勵人們維護BuildConfig.groovy和Maven POM。我會更新我的答案的正確性。 – rimero 2013-05-08 06:32:15