gradle错误:“您必须在应用Aspectj插件之前设置属性'aspectjVersion'";使用Kotlin DSL时 [英] gradle Error: "You must set the property 'aspectjVersion' before applying the aspectj plugin" when using kotlin DSL

查看:120
本文介绍了gradle错误:“您必须在应用Aspectj插件之前设置属性'aspectjVersion'";使用Kotlin DSL时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用Kotlin DSL的gradle项目中配​​置AspectJ插件.

I want to configure aspectJ plugin in my gradle project which is using kotlin DSL.

下面是我的 build.gradle.kts 文件.

    val aspectjVersion = "1.9.3"

    plugins {
        java
        id("aspectj.gradle") version "0.1.6"
    }

    group = "java-agents-demo"
    version = "1.0-SNAPSHOT"

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
    }

    dependencies {
        implementation("org.aspectj","aspectjrt", aspectjVersion)
        implementation("org.aspectj","aspectjweaver", aspectjVersion)
        testCompile("junit", "junit", "4.12")
    }

    configure<JavaPluginConvention> {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

当我运行 compileJava 项目时,出现错误消息您必须在应用Aspectj插件之前设置属性'aspectjVersion'".

When I run compileJava project I get error "You must set the property 'aspectjVersion' before applying the aspectj plugin".

我在构建文件中设置了 aspectjVersion ,但我不知道其中有什么错误.

I set aspectjVersion in my build file but I don't know what is the error in it.

有人可以帮助我以正确的方式为我的项目设置AspectJ插件吗?

Can anyone help me setup the aspectJ plugin for my project in correct way?

推荐答案

所以 val AspectjVersion ="1.9.3" 定义了局部变量,但是插件正在寻找项目属性,请注意这也意味着该插件不能立即应用,因为在 build.gradle.kts 的其余部分之前先评估了插件块(请参阅

So val aspectjVersion = "1.9.3" defines a local variable, but the plugin is looking for a project property, note that this also means the plugin can't be applied straight away as the plugins block is evaluated before the rest of the build.gradle.kts (see limitations of plugin DSL), try this instead:

val aspectjVersion by extra("1.9.3")

plugins {
    java
    id("aspectj.gradle") version "0.1.6" apply false
}

apply(plugin = "aspectj.gradle")

有关详细信息,请参见其他属性上的Gradle文档以了解详细信息.

See Gradle docs on extra properties for details.

这篇关于gradle错误:“您必须在应用Aspectj插件之前设置属性'aspectjVersion'";使用Kotlin DSL时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆