[GRADLE-1375] compileJava done before Datanucleus has enhanced classes Created: 06/Feb/11  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 0.9.2
Fix Version/s: None

Type: Bug
Reporter: Pieter Herroelen Assignee: Unassigned
Resolution: Won't Fix Votes: 1

Attachments: Zip Archive example.zip    

 Description   

When building a project that uses Datanucleus for persistence, classes are enhanced during 'compileJava'. compileJava returns too fast with status completed, before the enhancement of classes is complete.

Subsequent tasks, such as jar, will therefore use the non-enhanced classes.

See http://gradle.1045684.n5.nabble.com/compileJava-done-before-Datanucleus-has-enhanced-classes-tc3372540.html for the original thread in the Gradle users mailing list.

I've provided a test:

  • Run 'gradle clean test' > test fails, takes a while before you return to the command line
  • Then run 'gradle test -x compileJava' > test succeeds


 Comments   
Comment by Ashton Hepburn [ 01/Apr/11 ]

We're experiencing the same issue, running with: Gradle 1.0-milestone-1

That said both of the gradle commands listed above work for us. I could submit a test project (if useful), but it isn't substantively different.

As mentioned in the forum thread – I'm not seeing enhanced classes ending up in the .jar, this is easily verified by using javap to inspect them.

Is there a easy workaround?

Comment by James Wilson [ 04/Aug/11 ]

I worked around this problem by using the datanucleus ant task. Below is how I updated build.gradle from the attached example.zip. With these changes, the test passes.

apply plugin: 'java'

repositories {
	mavenCentral()
}

configurations {
 jdo {
 	extendsFrom compile
 }
}
dependencies {
   compile 'org.datanucleus:datanucleus-core:1.1.5',
           'javax.jdo:jdo2-api:2.3-eb'
	jdo 'org.datanucleus:datanucleus-enhancer:1.1.4'
   testCompile 'junit:junit:4.7'
    
}

task jdoEnhance << {
	ant.taskdef(name: 'enhancer', classname: 'org.datanucleus.enhancer.tools.EnhancerTask', classpath: configurations.jdo.asPath) 
	ant.enhancer( dir: sourceSets.main.output.classesDir.canonicalPath.toURI().toString(), verbose: 'true') {
		classpath {
			pathelement(location: sourceSets.main.output.classesDir.canonicalPath.toURI().toString())
			pathelement(path: configurations.jdo.asPath)
		}
		fileset(dir: sourceSets.main.output.classesDir.canonicalPath.toURI().toString()) {
			include(name: '**/*.class')
		}
	}
}

classes.dependsOn jdoEnhance
Comment by Jarosław Skrzypek [ 08/Apr/12 ]

Quote from http://www.datanucleus.org/products/datanucleus/enhancer.html#javac on running enhancer via annotations:
"Note that this works by waiting a period of time until all classes will have been compiled before invoking the enhancement step. We advise against using it, and better to use post-compile directly"

It looks like this is a limitation of running datanucleus enhancer via annotations rather than a gradle bug.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 11:53:57 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.