2012-07-18 65 views
4

我正在將Maven構建遷移到Gradle中,以依賴@Configurable Spring批註,但是當我的(web)應用程序運行時,沒有任何@Configurable類在Gradle下注入建立(他們正在精心打造我的Maven)。Gradle 1.0 + Spring + AspectJ構建問題

在Maven中我用下面的插件:

<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> 

對於搖籃1.0餘適於在0.9 AJC插件(以下URL),但不能弄清楚如何配置/ aspectLibraries /彈簧方面添加到這個:

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' 
} 

我需要做什麼才能讓Spring-aspects在Gradle構建的web應用程序中工作?

感謝

回答

1

我知道這個帖子是5歲,但我有答案,似乎沒有人在互聯網上做事情。雖然我使用Gradle 3.3(給我一個休息時間,這是2017年)。這是我的Gradle構建文件,可以使AWS SWF工作流和@Asynchronous標記一起工作。

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添加到依賴關係。花了我很多時間來弄清楚。