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

How to use Spoon and spoon-maven-plugin with Lombok? #5918

Open
ElvisLiaooo opened this issue Aug 7, 2024 · 3 comments
Open

How to use Spoon and spoon-maven-plugin with Lombok? #5918

ElvisLiaooo opened this issue Aug 7, 2024 · 3 comments

Comments

@ElvisLiaooo
Copy link

Lombok is widely used in my projects. I read some issues and still cannot figured out how to use spoon-maven-plugin with Lombok.

Try1: use spoon-maven-plugin, without any extra configuration with Lombok.
Apparently, error occurs in Launcher.buildModel() phase if any invalid gramma in the source file such as:

  • using @builder and define final fields
@Builder
@ToString
@Getter
public class SomeBuilderModel {
    private final int id;

    private final String name;
}
@AllArgsConstructor
public enum SomeConstructorTest {
    A(1),
    B(2);
    private final int id;
}

Try2: using delombok with lombok-maven-plugin, configure sourceDirectory to src/main/java

<plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.18.20.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.30</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>fr.inria.gforge.spoon</groupId>
                <artifactId>spoon-maven-plugin</artifactId>
                <version>3.8.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <processors>
                        <processor>
                            ProcessorA
                        </processor>
                        <processor>
                            ProcessorB
                        </processor>
                    </processors>
                </configuration>
            </plugin>

but it also failes because spoon maven plugins regard original sources and delombok generated source both as input source, which produces duplicated class, error:
The type XXXX is already defined

So is there any ways to configure spoon-maven-plugin to run with Lombok?

@MartinWitt
Copy link
Collaborator

Could you provide an minimal example project for the delombok approach? Spoon itself has no lombok support, so the first approach will never work.

@ElvisLiaooo
Copy link
Author

Could you provide an minimal example project for the delombok approach? Spoon itself has no lombok support, so the first approach will never work.

Yes, I figured it out that the first approach would not work definitely, so for the first approach, my question is, is it possible to provide an option to skip errors in buildModel() method? In code transformation scenario, we don't always need the complete AST model to generate code.

Also I've already solve this problem by modify the maven-plugin myself to integrate delombok inside, but most of the configurable options are hardcoded to simply the work. I think the official spoon-maven-plugin should also provide a complete version of delombok integration since Lombok is widely use in industry now.

@monperrus
Copy link
Collaborator

@ElvisLiaooo That should work if you add <noClasspath>true</noClasspath> to the <configuration> block of the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants