publicissapient-france/selma

Lombok

robertmircea opened this issue · 11 comments

How can I use Selma together with Lombok? It seems that Selma does not see the getters/setters generated by Lombok.

Failed to generate mapping method for type ..OtpData to .....resources.OtpDataResource not supported on ....model.OtpData --> Add a custom mapper or 'withIgnoreFields' on @Mapper or @Maps to fix this ! If you think this a Bug in Selma please report issue here

The only way to get it work is to build separate jars :
one for lombok enabled beans and the other with selma.

@slemesle, it's clear the issue with Lombok is just that at the time that Selma checks for a certain getter or setter method, Lombok processor didn't run, leading to Selma to fail. However, I think that if we would have a way to tell Selma, hey, don't worry if you don't find getters or setters, they will be available in runtime, it could continue generating mappers and complete successfully. In addition, when Maven (or whatever you use) completes, all the generated code should compile seamlessly too.

I'm sorry if I'm oversimplifying or missing anything important, but would that be possible? Would it possible adding a parameter to @Mapper such as withIgnoreNonexistentAccessors={true, false} to ignore nonexistent getters and setters?

Solving this issue would be really appreciated, and would make Selma way more flexible.

Thank you!

Yep, I'm facing this issue and will probably have to not use Selma because of it.
Shame really.

Lombok is a compile time annotation pre-processor, so is selma.
Isn't it possible to setup the build so that selma runs "after" lombok and thus can use the lombok generated code ? It seems processors run in multiple rounds It might be worth trying not to fail on the first processing round (maybe log a warning - and make it configurable) and retry generation in the next round, and only fail on processingIsOver if there remain types with missing getter/setters.

The only solution as of today, is to have your beans in a separate module than your mapper is. This way maven (or whatever you have) will compile your beans first and then your mapper, making the whole process possible.

I was able to generate the Lombok + Selma classes with:

pom.xml file:

<plugins>
   <build>    
      <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <defaultOutputDirectory>
                    ${project.build.directory}/generated-sources/selma
                </defaultOutputDirectory>
                <processors>
                    <processor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>                   
                    <processor>fr.xebia.extras.selma.codegen.MapperProcessor</processor>
                </processors>             
            </configuration>
            <executions>
                <execution>
                    <id>process</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>process</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>fr.xebia.extras</groupId>
                    <artifactId>selma-processor</artifactId>
                    <version>0.15</version>
                </dependency>
            </dependencies>
  </plugin>
 </plugins>
</build>

then : mvn generate-sources

Hi @anaice, thanks for this update.
Is it possible for you to provide a short sample project we can include in the source tree and point to it from the documentation ?

I was able to run a spring-boot project using a slightly modified maven 'build' tag:

<build>
	<plugins>
		<!-- Spring Boot Maven -->
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>

		<plugin>
			<groupId>org.bsc.maven</groupId>
			<artifactId>maven-processor-plugin</artifactId>
			<version>3.3.1</version>
			<configuration>
				<defaultOutputDirectory>
					${project.build.directory}/generated-sources/selma
				</defaultOutputDirectory>
				<processors>
					<processor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>
					<processor>fr.xebia.extras.selma.codegen.MapperProcessor</processor>
				</processors>
			</configuration>
			<!--executions>
				<execution>
					<id>process</id>
					<phase>generate-sources</phase>
					<goals>
						<goal>process</goal>
					</goals>
				</execution>
			</executions-->
			<dependencies>
				<dependency>
					<groupId>fr.xebia.extras</groupId>
					<artifactId>selma-processor</artifactId>
					<version>1.0</version>
				</dependency>
			</dependencies>
		</plugin>
	</plugins>

	<pluginManagement>
		<plugins>
			<!--This plugin's configuration is used to store Eclipse m2e settings 
				only. It has no influence on the Maven build itself. -->
			<plugin>
				<groupId>org.eclipse.m2e</groupId>
				<artifactId>lifecycle-mapping</artifactId>
				<version>1.0.0</version>
				<configuration>
					<lifecycleMappingMetadata>
						<pluginExecutions>
							<pluginExecution>
								<pluginExecutionFilter>
									<groupId>org.codehaus.mojo</groupId>
									<artifactId>aspectj-maven-plugin</artifactId>
									<versionRange>[1.0,)</versionRange>
									<goals>
										<goal>process</goal>
										<goal>test-compile</goal>
										<goal>compile</goal>
									</goals>
								</pluginExecutionFilter>
								<action>
									<execute />
								</action>
							</pluginExecution>
						</pluginExecutions>
					</lifecycleMappingMetadata>
				</configuration>
			</plugin>
		</plugins>
	</pluginManagement>
</build>

Observe that I commented out the in the maven-processor-plugin. I can run a spring-boot project with both lombok and selma with mvn -U clean spring-boot:run. Just add this build section to your projects pom.xml. The 'pluginManagement' section is for solving the Eclipse “Plugin execution not covered by lifecycle configuration”.

I am able to solve this issue by proper selection of lombok and selma version.
Below is the sample code from my build.gradle file:-
dependencies { compileOnly("org.projectlombok:lombok:1.16.14") compileOnly("fr.xebia.extras:selma-processor:1.0") compile("fr.xebia.extras:selma:1.0") }

Note that Lombok 1.16.14 or newer is required.

@ajay-kmr This trick was working for me until now. Don't know what's happening, perhaps the upgrade of Gradle.

Worked for me too !!