freefair / gradle-plugins

Gradle Plugin Collection
https://docs.freefair.io/gradle-plugins/current/reference/
MIT License
217 stars 32 forks source link

Groovy Test Project Config #422

Open moeniebdavids opened 2 years ago

moeniebdavids commented 2 years ago

Hi,

Is there any special config required to have groovy gradle test projects work with AspectJ plugin? When I run my tests, I keep getting the below [AppClassLoader@73d16e93] error aspect 'MYASPECT' (contained in a dependancy jar which is added via gradle dependancy) woven into 'xxxxxxxxx' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).

When I add a test to my main (src\main\groovy) I can execute perfectly. Its just with the test task that my aspects do not seem to apply

In terms of my build,gradle, I add

in plugin:

    id "io.freefair.aspectj.post-compile-weaving" version "5.1.0"

in dependancy:

    compile group: 'com.xxx', name: 'aspectStuff', version: '2.1'
    aspect 'com.xxx:aspectStuff:2.1'
    testCompile group: 'com.xxx', name: 'aspectStuff', version: '2.1'
    testAspect 'com.xxx:aspectStuff:2.1'
moeniebdavids commented 2 years ago

@larsgrefer Apologies for the direct tagging, but any chance I can get your expertise on this?

larsgrefer commented 2 years ago

Have you tried this:?

https://github.com/freefair/gradle-plugins/blob/148a41ea8c80386e08137ca34f811cd1d394c621/examples/aspectj/test/build.gradle#L10

moeniebdavids commented 2 years ago

Hi @larsgrefer Should this work if the aspects are contained in a dependancy jar? Also, this is a test project with no main sourceset. I am still getting [AppClassLoader@73d16e93] error aspect 'com.xxx.aspects.xxxxxxx.xxxAspect' woven into 'com.xx.repo.Control' must be defined to the weaver (placed on the aspectpath, or defined in an aop.xml file if using LTW).

plugins {
    id 'java'
    id 'groovy'
    id 'io.qameta.allure' version '2.8.1'
    id "io.freefair.aspectj.post-compile-weaving" version "5.1.0"
}

group 'com.example'
version '1.0-SNAPSHOT'

repositories {

    mavenLocal()
    mavenCentral()
}

ext {
    allureVersion = '2.14.0'
    junitVersion = '5.7.1'
}

sourceCompatibility = '8'
targetCompatibility = '8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

dependencies {
    implementation('org.codehaus.groovy:groovy:3.0.8')
    testImplementation('org.seleniumhq.selenium:selenium-java:4.0.0')
    testImplementation('org.slf4j:slf4j-simple:1.7.30')

    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

    testImplementation group: 'com.xx', name: 'xxxxxx', version: '2.2'
    testAspect 'com.xx:xxxxxx:2.2'
    testImplementation "org.aspectj:aspectjrt:1.9.5"
}

compileTestJava.ajc.options.aspectpath.from sourceSets.main.output
compileTestGroovy.ajc.options.aspectpath.from sourceSets.main.output

test {
    useJUnitPlatform()
}
allure {
    autoconfigure = true
    version = "${allureVersion}"

    useJUnit5 {
        version = "${allureVersion}"
    }
}
moeniebdavids commented 2 years ago

Please note this is a groovy project

-aspectpath contains /home/xxx/.gradle/caches/modules-2/files-2.1/com.xx/xxxx/2.2/e6e6fc4ecdac081573d279e6e2365ed7c016b096/testBuddy-2.2.jar: /home/xxx/.gradle/caches/modules-2/files-2.1/org.aspectj/aspectjrt/1.9.5/dc063f2557f6734ccb529b4c1d97132e4c8c739/aspectjrt-1.9.5.jar: and a few other jars

-inpath /home/xxx/Downloads/demo2/build/classes/groovy/test