0

我在我的 BuildConfig.groovy 文件的块中定义了以下自定义解析器,repositories{...}以便我可以获得在我的 Grails 项目中使用 JAI 所需的 jar。

mavenRepo "http://www.mygrid.org.uk/maven/repository"
def jbossResolver = new org.apache.ivy.plugins.resolver.URLResolver()
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/com/sun/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/javax/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.setName("AwesomestJbossResolverEver")
resolver jbossResolver

但是,每当我运行时grails refresh-dependencies,我都会收到此错误:

    compile (
        "net.java.dev.jai-imageio:jai-imageio-core-standalone:1.2-pre-dr-b04-2013-04-23",
        "javax.media:jai-core:1.1.3",
        "com.sun.media:jai-codec:1.1.3"
        ) 

jai-imageio-core-standalone 从http://www.mygrid.org.uk/maven/repository位置解析得很好,但是 jai-core 和 jai-codec 文件一直抛出这个错误:

| Error Failed to resolve dependencies (Set log level to 'warn' in BuildConfig.groovy for more information):    
- javax.media:jai-core:1.1.3
- com.sun.media:jai-codec:1.1.3

通过一些详细的日志记录,我发现了这个错误:

tried https://repository.jboss.org/nexus/content/groups/public-jboss/com/sun/media/jai-codec/1.1.3/jai-codec-1.1.3.jar
null: no ivy file found for com.sun.media#jai-codec;1.1.3: using default data
problem occurred while resolving dependency: com.sun.media#jai-codec;1.1.3 {compile=[default]} with null: java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:394)
    at java.util.Properties.setProperty(Properties.java:143)
    at org.apache.ivy.core.cache.DefaultRepositoryCacheManager.saveResolvers(DefaultRepositoryCacheManager.java:422)
    at org.apache.ivy.core.cache.DefaultRepositoryCacheManager.originalToCachedModuleDescriptor(DefaultRepositoryCacheManager.java:875)
......long stack trace here.........
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:234)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:262)
4

1 回答 1

0

在查看了Ivy 解析器文档DefaultRepositoryCacheManager 的 saveResolver() 方法之后

我发现问题在于我的自定义 jboss 解析器需要一个名称。我将repositories块的那部分更改为:

def jbossResolver = new org.apache.ivy.plugins.resolver.URLResolver()
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/com/sun/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/javax/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.setName("AwesomestJbossResolverEver")
resolver jbossResolver

只需使用 setName 方法添加名称即可摆脱该 nullPointer 异常。

值得注意的是,更仔细地阅读 Grails 文档会发现Grails 文档中关于自定义解析器的部分会暗示这个问题,因为它们的自定义 URLResolver 指定了名称和设置属性。低频磁场

于 2013-08-19T18:46:54.277 回答