Gradle 1.0 + Spring + AspectJ会产生问题 [英] Gradle 1.0 +Spring + AspectJ build problems

查看:175
本文介绍了Gradle 1.0 + Spring + AspectJ会产生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个Maven构建迁移到Gradle中,以依赖@Configurable Spring批注,但是当我的(web)应用程序运行时,没有任何@Configurable类在Gradle构建中注入(他们工作正常) Maven)。

I am migrating a Maven build into Gradle for a project relying on @Configurable Spring annotations, however when my (web) application is running none of the @Configurable classes are getting injected under the Gradle build (they were working fine built my Maven).

在Maven中,我使用了以下插件:

In Maven I used the following plugin:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.4</version>

        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                    <goal>test-compile</goal>
                </goals>
            </execution>
        </executions>

        <configuration>
            <aspectLibraries>
                <aspectLibrary>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
            </aspectLibraries>
            <source>${java.version}</source>
            <target>${java.version}</target>
        </configuration>
    </plugin>

对于Gradle 1.0,我调整了0.9 ajc插件(下面的url),但不知道如何将配置/ aspectLibraries / spring-aspects添加到这里:

For Gradle 1.0 I adapted the 0.9 ajc plugin (url below) but couldn't figure out how to add the configuration/aspectLibraries/spring-aspects into this:

    apply plugin: 'war'
apply plugin: 'jetty'

sourceCompatibility = 1.6
version = 1.0
// Based on: http://github.com/breskeby/gradleplugins/raw/0.9-upgrade/aspectjPlugin/aspectJ.gradle    
configurations {
    ajc
    aspects
    ajInpath
}

task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME, overwrite: true)  {
    dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava")

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

dependencies {
    ajc     group: 'org.aspectj',                     name: 'aspectjtools',                   version: '1.6.12'
    compile group: 'org.aspectj',                     name: 'aspectjrt',                      version: '1.6.12'
    compile group: 'org.aspectj',                     name: 'aspectjweaver',                  version: '1.6.12'

    compile group: 'org.springframework',             name: 'spring-jdbc',                    version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-orm',                     version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-aop',                     version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-aspects',                 version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-web',                     version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-webmvc',                  version: '3.1.1.RELEASE'
    compile group: 'org.springframework',             name: 'spring-expression',              version: '3.1.1.RELEASE'
}

我需要做些什么才能让Gradle构建Web应用程序中的spring-aspects?

What do I need to do to get spring-aspects working in Gradle built web applications?

谢谢

推荐答案

我知道这篇文章是5岁,但我有答案,似乎没有人在互联网上。虽然我使用Gradle 3.3(给我一个休息时间,这是2017年)。这里是我的Gradle构建文件,用于获取AWS SWF工作流和@Asynchronous标记的工作方式。

I know this post is 5 years old but I have the answer and it seems nobody else on the internet does. I'm using Gradle 3.3 though (Give me a break, it's 2017). Here's my Gradle build file to get AWS SWF Workflows along with @Asynchronous tags working.

buildscript {
    repositories {
        maven {
            url "https://maven.eveoh.nl/content/repositories/releases"
        }
    }

    dependencies {
        classpath "nl.eveoh:gradle-aspectj:1.6"
    }
}

project.ext {
    aspectjVersion = '1.8.9'
}

apply plugin: 'aspectj'
apply plugin: 'java'

dependencies {
    compile group: 'org.aspectj', name: 'aspectjrt', version:'1.8.9'
    compile group: 'org.aspectj', name: 'aspectjtools', version:'1.8.9'
    compile group: 'org.freemarker', name: 'freemarker', version:'2.3.25-incubating'
    compile group: 'com.amazonaws', name: 'aws-java-sdk-swf-libraries', version:'1.11.22'
    compile group: 'com.amazonaws', name: 'aws-swf-build-tools', version:'1.1'
    compile(group: 'org.springframework.boot', name: 'spring-boot-starter', version:'1.4.0.RELEASE') {
        exclude(module: 'commons-logging')
    }
    compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version:'1.4.0.RELEASE'
    testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.4.0.RELEASE') {
        exclude(module: 'commons-logging')
    }
    aspectpath group: 'com.amazonaws', name: 'aws-java-sdk-swf-libraries', version:'1.11.22'
}

引起我关注的关键是将aspectpath添加到依赖关系。花了我很多时间来弄清楚。

The key thing that caught me was adding the aspectpath to the dependencies. Took me ages to figure that out.

这篇关于Gradle 1.0 + Spring + AspectJ会产生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆