This is a short guide on how to make jcabi-aspects work with gradle projects. This approach will work with Java, Kotlin, Scala and Groovy. AOP Weaving First of all, add jcabi-aspects dependency into your build.gradle.kts file:

dependencies {
    implementation("com.jcabi:jcabi-aspects:${latestVersion}")
}

To make jcabi’s annotations work, we have to weave our classes with aspects from jcabi. To do this, we need a plugin which will modify our compiled sources. Best option is – freefair post-compile weaving plugin:

plugins {
    id("io.freefair.aspectj.post-compile-weaving") version "${latestVersion}"
}

After that, you should mark jcabi dependency as an aspect in dependencies:

dependencies {
    implementation("com.jcabi:jcabi-aspects:${latestVersion}")
    aspect("com.jcabi:jcabi-aspects:${latestVersion}")
}

For most cases, it should be enough. But if you have some plugins, which have their own compile tasks, you can face a problem like:

Execution failed for task ':service-name:someCompileTask'.
> Cannot infer AspectJ class path because no AspectJ Jar was found on class path

All you need to do is to expand your compile task with your classpath that contains aspectj.jar in your build.gradle.kts:

tasks.someCompileTask {
    configure<AjcAction> {
        classpath.setFrom(configurations.compileClasspath)
    }
}

Full version of build.gradle.kts is:

plugins {
    id("io.freefair.aspectj.post-compile-weaving") version latestVersion
}

dependencies {
    implementation("com.jcabi:jcabi-aspects:${latestVersion}")
    aspect("com.jcabi:jcabi-aspects:${latestVersion}")
}

// Only if you need
tasks.someCompileTask {
    configure<AjcAction> {
        classpath.setFrom(configurations.compileClasspath)
    }
}

Thanks!