gradle 如何将aspectJ导入到project中?

b1payxdu  于 2023-01-13  发布在  其他
关注(0)|答案(1)|浏览(150)

我需要使用aspectJ,如何使用这个lib/framework的功能?
这是我的build. gradle文件

plugins {
    id "com.diffplug.eclipse.apt" version "3.22.0"
    id "com.github.johnrengelman.shadow" version "7.0.0"
    id "application"
}

version "0.2"
group "ru.fusionsoft"

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

configurations {
    // for dependencies that are needed for development only
    developmentOnly
//    aspectjVersion: '1.9.9.1'
}

dependencies {
    implementation group: 'org.aspectj', name: 'aspectjrt', version: '1.9.9.1'
    implementation group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.9.1'
    implementation group: 'org.aspectj', name: 'aspectjtools', version: '1.9.9.1'
    implementation group: 'org.codehaus.mojo', name: 'aspectj-maven-plugin', version: '1.14.0'

    implementation "io.micronaut:micronaut-session:2.5.0"
    implementation "io.micronaut.redis:micronaut-redis-lettuce:2.5.0"
    implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.8'
    implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
    implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '3.0.0-RC1'
    implementation group: 'cglib', name: 'cglib', version: '3.3.0'
    implementation 'org.reflections:reflections:0.10.2'
    annotationProcessor(platform("io.micronaut:micronaut-bom:2.5.0"))
    annotationProcessor("io.micronaut:micronaut-inject-java:2.5.0")
    annotationProcessor("io.micronaut:micronaut-validation:2.5.0")
    implementation(platform("io.micronaut:micronaut-bom:2.5.0"))
    implementation("io.micronaut:micronaut-inject:2.5.0")
    implementation("io.micronaut:micronaut-validation:2.5.0")
    implementation("io.micronaut:micronaut-runtime:2.5.0")
    implementation("javax.annotation:javax.annotation-api:1.3.2")
    implementation("io.micronaut:micronaut-http-server-netty:2.5.0")
    implementation("io.micronaut:micronaut-http-client:2.5.0")
    runtimeOnly("ch.qos.logback:logback-classic")
    testAnnotationProcessor(enforcedPlatform("io.micronaut:micronaut-bom:2.5.0"))
    testAnnotationProcessor("io.micronaut:micronaut-inject-java:2.5.0")
    testImplementation(enforcedPlatform("io.micronaut:micronaut-bom:2.5.0"))
    testImplementation("org.junit.jupiter:junit-jupiter-api:2.5.0")
    testImplementation("io.micronaut.test:micronaut-test-junit5:3.0.0")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
    testImplementation "org.testcontainers:postgresql:1.14.3"
    annotationProcessor("io.micronaut.configuration:micronaut-openapi:1.5.3")
    implementation("io.swagger.core.v3:swagger-annotations")
    implementation("io.micronaut:micronaut-session:2.5.0")
    annotationProcessor ("io.micronaut.security:micronaut-security-annotations:2.5.0")
    implementation ("io.micronaut.security:micronaut-security-jwt:2.5.0")
    implementation("io.micronaut.sql:micronaut-jdbc-hikari:2.5.0")
    implementation("io.micronaut.sql:micronaut-hibernate-jpa:2.5.0")
    implementation("io.micronaut.data:micronaut-data-hibernate-jpa:2.5.0")
    annotationProcessor("io.micronaut.data:micronaut-data-processor:2.5.0")
    implementation group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'

    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
    implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'

    // https://mvnrepository.com/artifact/com.github.2captcha/2captcha-java
    implementation group: 'com.github.2captcha', name: '2captcha-java', version: '1.0.1'

    // https://mvnrepository.com/artifact/com.linuxense/javadbf
    implementation group: 'com.linuxense', name: 'javadbf', version: '0.4.0'

    // https://mvnrepository.com/artifact/org.apache.commons/commons-csv
    implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.8'

    // https://mvnrepository.com/artifact/org.apache.poi/poi
    implementation group: 'org.apache.poi', name: 'poi', version: '5.0.0'

    // https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils
    implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.13.1'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml
    implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.13.1'

    // Metrics
    implementation "io.micronaut.micrometer:micronaut-micrometer-core"
    implementation "io.micronaut.micrometer:micronaut-micrometer-registry-statsd"
    implementation "io.micronaut:micronaut-management"
    implementation 'io.micronaut.micrometer:micronaut-micrometer-registry-prometheus'
}


test.classpath += configurations.developmentOnly

mainClassName = "ru.fusionsoft.hcs.Application"

// use JUnit 5 platform
test {
    useJUnitPlatform()
}

java {
    sourceCompatibility = JavaVersion.toVersion('14')
    targetCompatibility = JavaVersion.toVersion('14')
}

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
    options.compilerArgs.addAll([
        '-parameters',
        // enables incremental compilation
        '-Amicronaut.processing.incremental=true',
        '-Amicronaut.processing.annotations=ru.fusionsoft.*',
        "-Amicronaut.processing.group=$project.group",
        "-Amicronaut.processing.module=$project.name",
    ])
}

shadowJar {
    mergeServiceFiles()
}

tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=default,swagger-ui.tagsSorter=\'alpha\',swagger-ui.operationsSorter=\'alpha\''
}

tasks.withType(JavaExec) {
    classpath += configurations.developmentOnly
    jvmArgs('-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
    if (gradle.startParameter.continuous) {
        systemProperties(
            'micronaut.io.watch.restart':'true',
            'micronaut.io.watch.enabled':'true',
            "micronaut.io.watch.paths":"src/main"
        )
    }
}

我最初没有写它,我也没有再使用过原语。显然,仅仅进入实现还不足以使用AOP。如果您需要更多的信息,我会更新。

crcmnpdw

crcmnpdw1#

将Maven插件添加到Gradle构建版本并希望它能神奇地在那里工作,这没有多大意义。顾名思义,aspectj-maven-plugin旨在用于Maven项目。您需要使用Gradle插件。也许您想看看AspectJ的Freefair插件,并确定哪种场景(以及哪种插件)适合您的用例。

相关问题