微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – AspectJ Gradle配置

我想在Gradle项目中使用AspectJ(它不是一个 Android项目 – 只是一个简单的Java应用程序).

以下是我的build.gradle的样子:

apply plugin: 'java'

buildscript {
    repositories {
        maven {
            url "https://maven.eveoh.nl/content/repositories/releases"
        }
    }
    dependencies {
        classpath "nl.eveoh:gradle-aspectj:1.6"
    }
}

repositories {
    mavenCentral()
}

project.ext {
    aspectjVersion = "1.8.2"
}

apply plugin: 'aspectj' 

dependencies {
    //aspectj dependencies
    aspectpath "org.aspectj:aspectjtools:${aspectjVersion}"
    compile "org.aspectj:aspectjrt:${aspectjVersion}"
}

代码编译,但方面似乎没有编织.可能有什么不对?

解决方法

我一直在努力解决这个问题,所以这个配置我用得很好.

在您的配置中执行此操作.

configurations {
    ajc
    aspects
    aspectCompile
    compile{
        extendsFrom aspects
    }
}

在依赖项中,使用以下配置.如果您不使用spring fwk,则不需要Spring依赖项.

dependencies {

    //Dependencies required for aspect compilation
    ajc "org.aspectj:aspectjtools:$aspectjVersion"
    aspects "org.springframework:spring-aspects:$springVersion"
    aspectCompile  "org.springframework:spring-tx:$springVersion"
    aspectCompile  "org.springframework:spring-orm:$springVersion"
    aspectCompile  "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:$hibernateJpaVersion"

}

compileJava {
    sourceCompatibility="1.7"
    targetCompatibility="1.7"
    //The following two lines are useful if you have queryDSL if not ignore
    dependsOn generateQueryDSL
    source generateQueryDSL.destinationDir

    dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true,"compileJava")

    doLast{
        ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjtaskdefs.properties",classpath: configurations.ajc.asPath)
        ant.iajc(source:"1.7",target:"1.7",destDir:sourceSets.main.output.classesDir.absolutePath,maxmem:"512m",fork:"true",aspectPath:configurations.aspects.asPath,sourceRootcopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath){
            sourceroots{
                sourceSets.main.java.srcDirs.each{
                    pathelement(location:it.absolutePath)
                }
            }
        }
    }
}

我不使用插件我使用ant和aspectj编译器来做到这一点,可能会有一个简单的方法

原文地址:https://www.jb51.cc/java/127446.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐