We've been putting together some (really simple) code in order to test out and introduce Lombok annotations into our project to make our code a bit nicer. Unfortunately, seems to break in testing, both through Maven and when the tests are run through IntelliJ.
Our domain classes look something like:
package foo.bar;
import lombok.Data;
@Data
public class Noddy {
private int id;
private String name;
}
With a corresponding test:
package foo.bar;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class NoddyTest {
@Test
public void testLombokAnnotations(){
Noddy noddy = new Noddy();
noddy.setId(1);
noddy.setName("some name");
assertEquals(noddy.getName(), "some name");
}
}
We have the aspectjrt dependency in Maven (as well as the relevant plugin in IntelliJ), and the aspectj-maven-plugin.
We're running with Maven 2-style POMs, JSDK 1.6.0_31, Lombok 0.11.0:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.0</version>
</dependency>
Are we doing something stupid or missing something obvious?
It would be great if we can get this working, as I've had an eye to using Lombok in production for some time now.
Many thanks,
P.
(FWIW, IntelliJ 11.1.2 has the Lombok plugin 0.4 and seems to be using ACJ for this project)
Avoid Test Interdependence You, therefore, cannot count on the test suite or the class that you're testing to maintain state in between tests. But that won't always make itself obvious to you. If you have two tests, for instance, the test runner may happen to execute them in the same order each time.
The @Ignore annotation helps in this scenario. A test method annotated with @Ignore will not be executed. If a test class is annotated with @Ignore, then none of its test methods will be executed.
The problem seems to be that the lombok generated code is overwritten by ajc, and according to a blog entry I found by Fabrizio Giudici, there is no "clean" Maven solution due to a bug in the Maven AspectJ plugin that prevents you from passing the necessary arguments to ajc.
He proposes a workaround here: http://weblogs.java.net/blog/fabriziogiudici/archive/2011/07/19/making-lombok-aspectj-and-maven-co-exist
Actually, this worked for me, and it's arguably a cleaner solution. You might have to add an execution phase for the test classes with an additional weave directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With