我想在Gradle项目中使用AspectJ(这不是Android项目-只是一个简单的Java应用程序).
I'd like to use AspectJ in Gradle project (it's not an Android project - just a simple Java app).
这是我的build.gradle的样子:
Here is how my build.gradle looks like:
apply plugin: 'java' buildscript { repositories { maven { url "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}" }代码可以编译,但是该方面似乎没有被编织.有什么问题吗?
The code compiles, however the aspect seems to not be weaved. What could be wrong?
推荐答案一段时间以来,我一直在为此苦苦挣扎,因此我使用的此配置效果很好.
I have been struggled with this for a while, so this the config I use and works well.
在您的配置中执行此操作.
In your configuration do this.
configurations { ajc aspects aspectCompile compile{ extendsFrom aspects } }在您的依赖项中,使用以下配置.如果您不使用spring fwk,则不需要Spring依赖项.
In your dependencies use the following configuration. Spring dependencies are not needed if you are not using spring fwk.
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:configurationspile.asPath){ sourceroots{ sourceSets.main.java.srcDirs.each{ pathelement(location:it.absolutePath) } } } } }我不使用我使用ant和Aspectj编译器进行的插件,可能会有一种简单的方法
I dont use the plugin I use the ant and aspectj compiler to do that, probably there will be an easy way
更多推荐
AspectJ + Gradle配置
发布评论