Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput


(Michael Vorburger) #1

I’m trying to bump https://github.com/apache/fineract from a (very, I know) old Gradle 2.10 to current 5.2.1 in https://github.com/apache/fineract/compare/develop...vorburger:bump-gradle-wrapper for https://issues.apache.org/jira/browse/FINERACT-700 and it fails saying:

Build file '/home/vorburger/dev/Mifos/git/fineract/fineract-provider/build.gradle' line: 77

* What went wrong:
A problem occurred evaluating root project 'fineract-provider'.
> Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.

that line 77 in https://github.com/apache/fineract/blob/develop/fineract-provider/build.gradle#L77 is:

openjpa {
    files = fileTree(sourceSets.main.output.classesDir).matching {
		include '**/AbstractPersistableCustom.class'
		include '**/domain/*.class'

    }
    enforcePropertyRestrictions = true
}

How do I adapt this so that it works with the current Gradle version?

Could not find property 'classesDir' on source set main is an older forum entry re. something that looks similar, but I don’t see how it applies here - it IS sourceSets.main.output.classesDir.


(René Groeschke) #2

Hey Michael,

File classesDir has been replaced by FileCollection classesDirs. so you should be able to use classesDirs.filter{} here.


(Michael Vorburger) #3

yup, thanks a lot, looks like this does the trick:

openjpa {
    files = fileTree(sourceSets.main.output.classesDirs.filter {
		include '**/AbstractPersistableCustom.class'
		include '**/domain/*.class'
    })
    enforcePropertyRestrictions = true
}

(Michael Vorburger) #4

but a have similar follow-up problem, related to http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle:

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir

so Gradle now supports several classesDirs but there is still only a single resourcesDir, so how does one upgrade in this case?


(uklance) #5

As a bit of background, I believe the SourceSetOutput.getClassesDir() changed to SourceSetOutput.getClassesDirs() so that you could compile java, groovy and/or scala etc in the same project with each task’s outputs separated so that UP-TO-DATE task skipping works properly. If your project only has java sources you could do

sourceSets.main.output.resourcesDir = sourceSets.main.java.outputDir
sourceSets.test.output.resourcesDir = sourceSets.test.java.outputDir

If you need a single classesDir and have groovy/scala and/or java in the same project you might need a copy task.

Eg:

task copyClasses(type: Copy) {
    dependsOn [compileJava, compileScala, compileGroovy] 
    sourceSets.main.output.classesDirs.each {
        from it
    } 
    into "$buildDir/allclasses" 
} 
task copyTestClasses(type: Copy) { ... } 
processResources.dependsOn copyClasses 
processTestResources.dependsOn copyTestClasses
sourceSets.main.output.resourcesDir = file("$buildDir/allclasses") 
sourceSets.test.output.resourcesDir = file("$buildDir/alltestclasses")

(Michael Vorburger) #6

Thanks, that works! (New problems unrelated to this in separate posts.)