我最近将App Engine项目从Eclipse迁移到Android Studio。不幸的是,appengineEnhance
gradle任务失败了。
我已经发现可能存在版本不匹配,因为org.datanucleus.OMFContext
不应出现在v2库中。所以我猜有些依赖是引用datanucleus-...-1.1.5
而不是datanucleus-...-3.1.3
,但我无法解决这个问题。
使用--info:
记录输出Executing task ':backend:appengineEnhance' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
App Engine SDK root = C:\Users\NTBDE\.gradle\appengine-sdk\appengine-java-sdk-1.9.42
Java classpath = C:\Users\NTBDE\.gradle\wrapper\dists\gradle-2.14.1-all\8bnwg5hd3w55iofp58khbp6yv\gradle-2.14.1\lib\gradle-launcher-2.14.1.jar;C:\Users\NTBDE\.gradle\appengine-sdk\appengine-java-sdk-1.9.42\lib\appengine-tools-api.jar
Webapp source directory = C:\Users\sschultz\Documents\Projects\IntelliQ\Android\IntelliQ\backend\src\main\webapp
Enhancing DataNucleus classes...
[ant:enhance] [newrelic.info] Deinstrumenting...
[ant:enhance] Encountered a problem: Unexpected exception
[ant:enhance] Please see the logs [C:\Users\sschultz\AppData\Local\Temp\enhance2770794418099399278.log] for further information.
Finished enhancing DataNucleus classes.
:backend:appengineEnhance FAILED
:backend:appengineEnhance (Thread[Daemon worker Thread 7,5,main]) completed. Took 0.589 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':backend:appengineEnhance'.
> An error occurred enhancing DataNucleus classes.
来自日志文件的Stacktrace:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
... 2 more
Caused by: java.lang.NoSuchMethodError: org.datanucleus.plugin.PluginManager.<init>(Lorg/datanucleus/PersistenceConfiguration;Lorg/datanucleus/ClassLoaderResolver;)V
at org.datanucleus.OMFContext.<init>(OMFContext.java:159)
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:172)
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:150)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1157)
... 7 more
build.gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
war.dependsOn appengineEnhance
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile group: 'com.google.apis', name: 'google-api-services-oauth2', version: 'v1-rev120-1.22.0'
compile group: 'com.google.http-client', name: 'google-http-client', version: '1.22.0'
compile group: 'com.google.http-client', name: 'google-http-client-appengine', version: '1.22.0'
compile group: 'com.google.http-client', name: 'google-http-client-jdo', version: '1.22.0'
compile group: 'com.google.http-client', name: 'google-http-client-gson', version: '1.22.0'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.2'
compile group: 'com.google.appengine.orm', name: 'datanucleus-appengine', version: '2.1.2'
compile 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'
compile 'javax.servlet:servlet-api:2.5'
compile 'javax.transaction:jta:1.1'
compile 'com.google.code.gson:gson:2.4'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
enhancer {
version = "v2"
api="jdo"
enhanceOnBuild = true
}
}
修改
我可以验证该进程正在使用v1 jar(尽管应该使用v2,如build.gradle中所述)。
从.gradle\appengine-sdk\appengine-java-sdk-1.9.42\lib\opt\tools\datanucleus
中删除v1文件夹时,任务失败,但出现以下异常:
java.lang.NullPointerException: ormLibs cannot be null
at com.google.appengine.tools.enhancer.EnhancerLoader.removeOrmLibs(EnhancerLoader.java:66)
at com.google.appengine.tools.enhancer.EnhancerLoader.getClassPath(EnhancerLoader.java:43)
at com.google.appengine.tools.enhancer.EnhancerLoader.<init>(EnhancerLoader.java:37)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:69)
at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
答案 0 :(得分:2)
好的,事实证明这是与最新版App Engine Java SDK相关的issue。
降级线
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
以下
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.38'
解决了所有错误,并且增强工作正常。
答案 1 :(得分:1)
我有类似的问题。您需要为增强器添加更多依赖项。这是我的build.gradle文件:
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'buls' at '8/30/16 11:36 PM' with Gradle 2.13
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/2.13/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}
def appEmail = "${appEmail}"
repositories {
jcenter()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.0'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.0'
compile 'com.google.code.gson:gson:2.2.2'
compile 'commons-codec:commons-codec:1.10'
compile 'org.json:json:20160810'
compile 'org.ow2.asm:asm:4.0'
compile 'com.google.appengine:appengine-api-labs:1.9.0'
compile 'com.google.appengine:appengine-jsr107cache:1.9.0'
compile 'org.datanucleus:datanucleus-api-jpa:3.1.3'
compile 'org.datanucleus:datanucleus-api-jdo:3.1.3'
compile 'com.google.appengine.orm:datanucleus-appengine:2.1.2'
compile 'org.datanucleus:datanucleus-core:3.1.3'
compile 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'
compile 'javax.jdo:jdo-api:3.0.1'
compile 'javax.transaction:jta:1.1'
compile 'net.sf.jsr107cache:jsr107cache:1.1'
}
appengine {
httpPort = 8888
downloadSdk = true
appcfg {
email = "${appEmail}"
noCookies = false
oauth2 = true
}
enhancer {
version = "v2"
enhanceOnBuild = true
api = "jdo"
}
}