AspectJ + Gradle配置

编程入门 行业动态 更新时间:2024-10-27 22:29:22
本文介绍了AspectJ + Gradle配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在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配置

本文发布于:2023-07-15 23:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AspectJ   Gradle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!