Could not get unknown property 'classesDir' for main classes

#1

According to the documentation, I’ve tried to use aspectj plugin.

This is the message I get when I build my project.

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jesudi/projects/gradle-vscode/build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'security'.
> Failed to apply plugin [id 'aspectj.gradle']
   > Could not create task ':compileAspect'.
      > Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.

This is my script:

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.apache.meecrowave:meecrowave-gradle-plugin:1.2.6"
        classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
    }
}

plugins {
    id 'java'
}

project.ext {
    aspectjVersion = '1.9.2'
}

apply plugin: 'aspectj.gradle'
apply plugin: "org.apache.microwave.microwave"

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
    compile("org.apache.meecrowave:meecrowave-core:1.2.6")
    compile("org.apache.meecrowave:meecrowave-specs-api:1.2.6")
}

meecrowave {
    httpPort = 9090
    // most of the meecrowave core configuration
}

This is the gradle -version output:

------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.2 (Oracle Corporation 11.0.2+9)
OS:           Linux 4.15.0-20-generic amd64
(uklance) #2

SourceSetOutput.getClassesDir() was deprecated in Gradle 4 and removed in Gradle 5. Please use getClassesDirs() in Gradle 5

https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSetOutput.html#getClassesDirs--

Unable to find method 'org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
(Daniel) #3

So this is a bug in the official aspectj plugin?

1 Like
(Daniel Arend) #4

Yes, I can confirm the problem. It seems to be a bug in the official AspectjGradlePlugin, so it is not (!) compatible with Gradle 5, which is very frustrating at the moment because I tried several other plugins, but this one was the only one that works well and without any complex configuration.

At the moment I cannot switch to Gradle 5 due to this shortcoming and I hope that it will be fixed very soon. Or is there any alternative/workaround? Where can we find the official source code for this plugin?

(uklance) #5

Unfortunately the plugin links to the Gradle website rather than its own website on the plugin portal

https://plugins.gradle.org/plugin/aspectj.gradle

(uklance) #6

There’s a sources jar here
https://plugins.gradle.org/m2/gradle/plugin/aspectj/gradle-aspectj/0.1.6/

(Daniel Arend) #7

Unfortunately this only confirms, that it is a bug in the source code due to the wrong function call “getClassesDir()”, I checked the code. But how can we fix it? There must be a Git to send a pull request or something like this !?

(uklance) #8

Exactly, it’s a third party plugin with little or no documentation. You’ll need to track that down yourself

(lambovg) #9

I face the same problem as you when compiling with ajc and gradle5. I patch the plugin, here are the changes on the original code: https://github.com/Apilytic/aspectj.gradle/commit/649a1d3ae898a0b104befcbe3e5cc985eff919f4
This changes are backwards compatibility with Gradle 4

Final goal is to be bundled as plugin. I start working on that.

So far integration is ugly - I paste the code in the build file: https://github.com/Apilytic/currency-converter/blob/master/build.gradle

(Daniel Arend) #10

Thank you for your effort. I also forked the project and published an updated plugin, but the frist time it was deleted (I don’t know why) and now it is still under approval…Maybe your plugin will be released faster, but anyway I’m happy to see some progress…

(lambovg) #11

Well Im far from it to package it as a plugin yet… also there are now warnings for gradle 6 there :slight_smile:

(lambovg) #12

I’ve just managed it to bundle it like a plugin and I’ve integrated successfully in my project: https://github.com/Apilytic/currency-converter/commit/ac92d14cbb70dccecf5b66bd78d4cfbf26d375be and you can see here plugin doc itself: https://github.com/Apilytic/aspectj.gradle/blob/master/README.md

Now integration is better.

2 Likes
(Daniel Arend) #13

Thank you very much of your effort.
Now finally my plugin for the Gradle Plugin Portal was accepted, feel free to comment:
https://plugins.gradle.org/plugin/aspectj.AspectjGradlePlugin

I marked all changed in the source code.
Now it is working with Gradle 5.

(Ameya Baburao Patil) #14

Thanks Lance, but could you please tell me what changes do I need to make to use getClassesDir() instead of SourceSetOutput.getClassesDir()? This is just my second day with Android App Development and I am struggling to make sense of the entire Gradle build system and process. Any help would be highly appreciated

(uklance) #15

The problem is that either your build.gradle or a plugin referenced in your build.gradle is using a method that was deprecated in Gradle 4 and removed in Gradle 5.

If its your build.gradle then you need to change it from using SourceSetOutput.getClassesDir() to SourceSetOutput.getClassesDirs()

If its a plugin, then possibly you are on an old version and updating to a newer version will fix. If not you might need to contact the plugin author to get a fix, or perhaps submit a pull request

You could run the following to get a better understanding of where the call is being made

gradle build --stacktrace