AspectJ + Gradle configuration

后端 未结 6 456
执念已碎
执念已碎 2021-02-04 11:31

I\'d like to use AspectJ in Gradle project (it\'s not an Android project - just a simple Java app).

Here is how my build.gradle looks like:

apply plugin         


        
6条回答
  •  时光说笑
    2021-02-04 12:21

    Just want to add the so called "official" plugin for AspectJ mentioned by Archie.

    Here's some gradle script example on how to do it:

    apply plugin: 'java'
    
    
    
    sourceCompatibility = '1.8'
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
    
    if (!hasProperty('mainClass')) {
        ext.mainClass = 'com.aspectz.Main'
    }
    buildscript {
      repositories {
        maven {
          url "https://plugins.gradle.org/m2/"
        }
      }
      dependencies {
        classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
        //classpath "gradle.plugin.aspectj:plugin:0.1.1"
        //classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.1"
      }
    }
    
    
    ext {
        aspectjVersion = '1.8.5'
    }
    
    apply plugin: "aspectj.gradle"
    
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
    
        testCompile group: 'junit', name: 'junit', version: '4.10'
        compile("log4j:log4j:1.2.16")
        compile("org.slf4j:slf4j-api:1.7.21")
        compile("org.slf4j:slf4j-log4j12:1.7.21")
        compile("org.aspectj:aspectjrt:1.8.5")
        compile("org.aspectj:aspectjweaver:1.8.5")
    
    
    }
    

    However, it seems that it only supports Java 8 and above. As when you use java 7 to build it, it got error :

    java.lang.UnsupportedClassVersionError: aspectj/AspectJGradlePlugin : Unsupported major.minor version 52.0
    

提交回复
热议问题