0

I've got a mixed Scala/Java maven project where the application code, unit and integration tests are written in Java but performance tests are written in Scala.

The Scala performance tests depend on a couple Java Integration Test classes that have @Data Lombok annotations. In order for getters and setters to work I must compile JavaThenScala, which I can do through IntelliJ Scala Compiler settings.

My question is - Is there a way I can set my maven plugins to do the JavaThenScala compilation without adjusting the IntelliJ settings since I would like to deploy the code elsewhere?

I am trying to use the compileOrder configuration but it doesn't seem to do the trick for me.

My maven plugins:

  <build>
    <plugins>
      <plugin>
        <groupId>met.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>4.0.0</version>
        <configuration>
            <compileOrder>JavaThenScala</compileOrder>
        </configuration>
      </plugin>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>3.1.1</version>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
Kris
  • 562
  • 5
  • 17
  • what happen when you run `mvn clean package`? – JRichardsz Sep 10 '21 at 14:07
  • hey @JRichardsz, I see `Error: value getVariable is not a member of the Class` where it is located under @Data annotation. If I change @Data to an actual getter ,it works or if I change Scala compiler setting on IntelliJ to JavaThenScala and re-compile it works as well – Kris Sep 10 '21 at 14:18
  • I'm not sure scala-maven-plugin works properly with Java annotation processing. – Stéphane LANDELLE Sep 10 '21 at 14:21
  • Where does your error occur? In your scala test, right? It would be helpful if you share a mvp of your project. A simple spring bean with its test. – JRichardsz Sep 10 '21 at 14:21
  • It is some strange. mvn package first compile all the java class , then the tests and after that runs the test – JRichardsz Sep 10 '21 at 14:27

1 Answers1

5

Disclaimer: Gatling founder and scala-maven-plugin co-maintainer here

Annotation processing, in particular Lombok, is a super weird beast. It seems scala-maven-plugin doesn't support it, see https://github.com/davidB/scala-maven-plugin/issues/342 (was closed due to lack of activity/contribution).

Then, I recommend you isolate your Gatling tests in a dedicated module, so you can build your Lombok based test classes in a pure Java module that would publish a test jar and then have your Gatling module depend on this test-jar.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
  • 1
    Thanks for looking into it! I feel like at this point I might just add an actual getter instead of lombok @Data annotation for the few variables I need for Scala and roll with that. Not the prettiest option but it will work. – Kris Sep 10 '21 at 15:47
  • For your information, Gatling 3.7 will bring a Java DSL too. – Stéphane LANDELLE Sep 10 '21 at 16:00
  • 1
    Agree, just not using Lombok in the few places you need might be the easiest solution. – Stéphane LANDELLE Sep 10 '21 at 16:02
  • Ended up just creating a method `getScalaValues()` in my `TestUtils.java` class that gets all values I need using lombok and puts them in a hashmap. Then just created a `val scalaValues: util.Map[String, String] = TestUtils.getScalaValues` in Scala and used it to populate the fields. That was the cleanest solution I could come up with since I am not that worried about it being a bit slower. – Kris Sep 10 '21 at 18:28