Skip to content

[Bug]: Duplicate classes when trying to compile in IntelliJ #6419

@adamretter

Description

@adamretter

Describe the bug

If you use the spoon-maven-plugin in your project, it then seems that you can no longer compile the project in IntelliJ as you get errors about java: duplicate class: MyClass for every class that is processed by spoon.

I believe that this is because src/main/java contains a copy of the class (.java) file, and then also target/generated-sources/spoon contains another (processed) copy of the class (.java) file.

IntelliJ doesn't seem to understand that the original copy in src/main/java should be ignored, and there seems to be no easy way to configure this (e.g. remove src/main/java as a source root) without breaking many things.

NOTE - the build still works fine outside of IntelliJ when using mvn from the CLI; but IntelliJ is probably the most popular IDE, and we need to use it here.

Any ideas?

Source code you are trying to analyze/transform

Example Maven plugin config from pom.xml:

<plugin>
    <groupId>fr.inria.gforge.spoon</groupId>
    <artifactId>spoon-maven-plugin</artifactId>
    <version>3.8.0</version>
    <executions>
        <execution>
            <id>spoonify</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <compliance>21</compliance>
                <noCopyResources>true</noCopyResources>
                <processors>
                    <processor>xyz.elemental.build.tools.spoon.processors.PermissionRequiredProcessor</processor>
                </processors>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>fr.inria.gforge.spoon</groupId>
            <artifactId>spoon-core</artifactId>
            <version>11.2.1</version>
        </dependency>
        <dependency>
            <groupId>xyz.elemental</groupId>
            <artifactId>exist-core-build-tools</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</plugin>

Spoon Version

spoon: 11.8.2
spoon-maven-plugin: 3.8.0
IntelliJ: 2025.2.1

JVM Version

21

What operating system are you using?

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions