You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin Gradle项目中Freefair AspectJ插件配置失效求助

Kotlin Gradle项目配置Freefair AspectJ插件切面不生效问题

我在Kotlin Gradle项目中配置Freefair AspectJ插件时遇到问题:应用启动无异常,但切面未生效。我将切面文件MetricAspect.kt放置在src/main/aspectj源码目录下,当前build.gradle.kts配置如下:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    //other plugins

    id("io.freefair.aspectj") version "6.6.3"

    val kotlinVersion = "1.7.21"
    kotlin("jvm") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion

    //other plugins
}

allprojects {
    apply(plugin = "org.jetbrains.kotlin.jvm")
    apply(plugin = "io.gitlab.arturbosch.detekt")
    apply(plugin = "com.diffplug.spotless")
    apply(plugin = "io.freefair.aspectj")
    apply(plugin = "kotlin-spring")
    version = "1.0.0-SNAPSHOT"

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

    repositories {
        maven {
            url = uri("https://private.repo/public-maven-virtual/")
            credentials {
                username = user
                password = password
            }
        }
    }

    dependencies {

        kotlinCompilerPluginClasspath("gradle.plugin.aspectj:gradle-aspectj:0.1.6")
        
        //other deps

        implementation("org.aspectj:aspectjrt:1.9.7")
        annotationProcessor("org.aspectj:aspectjtools:1.9.7")

        //other deps
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "17"
        }
    }

    tasks.withType<Test> {
        useJUnitPlatform()
    }

    spotless {
        //....
    }

    detekt {
        buildUponDefaultConfig = true // preconfigure defaults
        allRules = false // activate all available (even unstable) rules.
        parallel = true
        config = files("$rootDir/detekt.yml")
    }
}

tasks {
    bootJar {
        enabled = false
    }
}

相关文档十分匮乏,且配置方式众说纷纭,请问是否有官方标准配置方式?


内容的提问来源于stack exchange,提问作者L_Cleo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 01:42:36