Steppschuh Steppschuh - 2 months ago 27
Java Question

DataNucleus enhancing failed - GAE in Android Studio

I recently migrated an App Engine project from Eclipse to Android Studio. Unfortunately the

appengineEnhance
gradle task fails.

I already figured out that there might be a version mismatch, as
org.datanucleus.OMFContext
shouldn't be present in the v2 libs. So I guess that some dependency is referencing
datanucleus-...-1.1.5
instead of
datanucleus-...-3.1.3
but I'm not able to resolve this issue.

Log output with --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 from log file:

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 file:

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
}
}


Edit:
I can verify that the process is using the v1 jars (although v2 should be used, as stated in build.gradle).
When removing the v1 folder from
.gradle\appengine-sdk\appengine-java-sdk-1.9.42\lib\opt\tools\datanucleus
, the tasks fails with the following exception:

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)

Answer

Alright, turns out this is an issue related to the latest version of the App Engine Java SDK.

Downgrading the line

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'

to the following

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.38'

resolved all errors and the enhancing works fine.

Comments