Gradle

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
To raise new issues or bugs against Gradle, please use forums.gradle.org.
  • Gradle
  • GRADLE-1375

compileJava done before Datanucleus has enhanced classes

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Resolution: Unresolved
  • Affects Version/s: 0.9.2
  • Fix Version/s: None

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
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    example.zip
    06/Feb/11 7:14 AM
    10 kB
    Pieter Herroelen
    1. File
      example/build.gradle 0.2 kB
    2. File
      example/.gradle/.../cache.properties 0.0 kB
    3. File
      example/.gradle/.../taskArtifacts/cache.bin 91 kB
    4. Java Source File
      example/src/main/.../sample/Example.java 0.3 kB
    5. Java Source File
      example/src/test/.../sample/ExampleTest.java 0.6 kB
    Download Zip
    Show
    Zip Archive
    example.zip
    06/Feb/11 7:14 AM
    10 kB
    Pieter Herroelen

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • TeamCity
  • Commits
  • Source
  • Reviews
Hide
Permalink
Ashton Hepburn added a comment - 01/Apr/11 10:11 AM

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?

Show
Ashton Hepburn added a comment - 01/Apr/11 10:11 AM 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?
Hide
Permalink
James Wilson added a comment - 04/Aug/11 4:42 PM

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
Show
James Wilson added a comment - 04/Aug/11 4:42 PM 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
Hide
Permalink
Jarosław Skrzypek added a comment - 08/Apr/12 12:49 PM

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.

Show
Jarosław Skrzypek added a comment - 08/Apr/12 12:49 PM 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.

People

  • Assignee:
    Unassigned
    Reporter:
    Pieter Herroelen
Vote (1)
Watch (1)

Dates

  • Created:
    06/Feb/11 7:13 AM
    Updated:
    08/Apr/12 12:49 PM
  • Atlassian JIRA (v5.0.3#729-sha1:bf569e4)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Gradle. Try JIRA - bug tracking software for your team.