Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compileTestAspect can't compile Classes with static fields #218

Closed
superwese opened this issue Dec 9, 2020 · 5 comments
Closed

compileTestAspect can't compile Classes with static fields #218

superwese opened this issue Dec 9, 2020 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@superwese
Copy link

What were you trying to accomplish?
I have a class that resembles a respository. In this class a have a

public class VatRepository extends DynamoRepository<VatEntity> {
    public static String VATENTITY_TABLE_VAR_NAME = "VAT_TABLE_NAME";

In my tests, I am trying to access this field to set a system property:

    @BeforeAll
    void setup() {

        System.setProperty(VatRepository.VATENTITY_TABLE_VAR_NAME, "vatTable-test");

when I run the tests I get this error from the compileTestAspect :

0::0 VATENTITY_TABLE_VAR_NAME cannot be resolved or is not a field

This is not happening in the compileAspect task, that produces the production code.
Is there anything I can do that the AspectJ plugin is not trying to compile my classes?

I am building with gradle.

Expected Behavior

It should compile

Steps to Reproduce (for bugs)

  1. create a class with a static property and use it in tests.

Environment

  • Powertools version used: 1.1.0
  • Packaging format (Layers, Maven/Gradle): Gradle
  • AWS Lambda function runtime: java11
  • Debugging logs

Gradle.build:

plugins {
    id 'java'
    id 'aspectj.AspectjGradlePlugin' version '0.0.6'

}

sourceCompatibility = 1.11
targetCompatibility = 1.11

repositories {
    jcenter()
    maven {
        name "DynamoDB Local Release Repository - EU (Frankfurt) Region"
        url "https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release"
    }

}

dependencies {
    implementation platform('software.amazon.awssdk:bom:2.15.40')
    implementation 'software.amazon.awssdk:dynamodb'
    //https://aws.amazon.com/de/blogs/developer/introducing-enhanced-dynamodb-client-in-the-aws-sdk-for-java-v2/
    implementation 'software.amazon.awssdk:dynamodb-enhanced'
    implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
    implementation 'com.amazonaws:aws-lambda-java-events:2.2.9'
    implementation 'software.amazon.lambda:powertools-sqs:1.1.0'
    aspectpath 'software.amazon.lambda:powertools-sqs:1.1.0'

    implementation 'io.burt:jmespath-jackson:0.5.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

    // Use JUnit Jupiter
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
    testImplementation 'org.hamcrest:hamcrest:2.2'

    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    testCompile group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.13.5'
    testCompile group: 'org.jeasy', name: 'easy-random-core', version: '5.0.0'
    testCompile group: 'org.jeasy', name: 'easy-random-core', version: '5.0.0'
    testCompile group: 'org.jeasy', name: 'easy-random-bean-validation', version: '5.0.0'
    testCompile group: 'org.jeasy', name: 'easy-random-randomizers', version: '5.0.0'

}
task copyNativeDeps(type: Copy) {
    from(configurations.compile + configurations.testCompile) {
        include '*.dll'
        include '*.dylib'
        include '*.so'
    }
    into 'build/libs'
}


test {
    // Use junit platform for unit tests.
    dependsOn copyNativeDeps
    systemProperty "java.library.path", 'build/libs'
    useJUnitPlatform()
}

gradle.properties:

aspectjVersion=1.9.6

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
@superwese superwese added the bug Something isn't working label Dec 9, 2020
@superwese
Copy link
Author

a workaround I found for that ist to run

./gradlew clean build -x test

before running the test.
This way the source code is already compiled and AspectJ at least doesn't pick up the production code.
Test classes are still affected.

@pankajagrawal16 pankajagrawal16 added the help wanted Extra attention is needed label Jan 13, 2021
@pankajagrawal16
Copy link
Contributor

Hi @superwese Thanks for reporting the issue. I will have a look at this sometime this week.

@somayaj
Copy link

somayaj commented Oct 20, 2021

Hi, can this issue be worked on? Please advise.

Thanks, Asha.

@pankajagrawal16
Copy link
Contributor

Hi @somayaj / @superwese

Apologies for delay, but this looks like an upstream bug with Gradle aspectj.AspectjGradlePlugin plugin. I will try following this up with the upstream.

Similar problem does not exists when working with maven project.

@pankajagrawal16
Copy link
Contributor

pankajagrawal16 commented Oct 25, 2021

Hi Again @somayaj

I tried to replicate the above issue, the problem seems to only occur when you already have a build folder created locally with classes before you introduced static field dependancy.

Once you delete the locally created temp build folder created from before, it works fine. Let me know if this solves your issue.

Closing the issue for now.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants