我在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)
答案 0 :(得分:0)
审核Ivy resolver documentation和DefaultRepositoryCacheManager's saveResolver() method
后我发现问题是我的自定义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 Documentation部分暗示问题,因为他们的自定义URLResolver指定了名称和设置属性。 LFMF