For some time now, I’ve had a problem in VsCode where I end up with duplicate generated sources.
For example, let’s take the SiteEntity entity.
In /target/generated-sources/annotations/com/…/sites, I’ll find two classes:
SiteEntity.java
SiteEntity.java
In the first one, in error, I have the following imports !
package jakarta.persistence.metamodel;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
in the second :
package com.oxand.simeox.inventory.sites.data;
import com.....BuildingEntity; // these are client imports
import com......WorkspaceEntity; // these are client imports
import jakarta.annotation.Generated;
import jakarta.persistence.metamodel.EntityType;
import jakarta.persistence.metamodel.ListAttribute;
import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.StaticMetamodel;
import java.time.LocalDateTime;
it’s like there is two code generators writing when building.
i tried to clean workspace, mvn clean install, reload the project, reload vscode, reload Windows …
as asked by @aled
here is my extensions :
- Debugger for Java v0.58.0
- Extension Pack for Java 0.27.2024062708
- Language Support for Java(TM) by Red Hat 1.32.0
- Maven for Java 0.44.0 SonarLint 4.7.0
- Project Manager for Java v0.23.7
- Test Runner for Java 0.41.1
and some extensions no related
- Test Explorer UI
- Test Adapter Converter
- SQLTools PostgreSQL/Cockroach Driver
- SQLTools v0.28.3
- Prettier – Code formatter v10.4.0
- IntelliCode API Usage Examples v0.2.8
- IntelliCode v1.3.1
- Increment Selection v0.2.0
- Git History v0.2.4
- EditorConfig for VS Code v0.16.4
2
Answers
This should be caused by multiple code generators or annotation processors running during your build process.
You could do the following steps to check your project:
pom.xml
orbuild.gradle
file.mvn clean install
orgradle clean build
to ensure that all old generated source code is removed and regenerated. And you could run Java: Clean Java Language Server Workspace in VSCode Command Palette.The problem is here and a workaround is to override the version of Jpamodelgen to 6.4.8.Final as explained here. Worked for me.