skip to Main Content

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


  1. 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:

    1. Check for Duplicate Annotation Processors: please ensure that you don’t have multiple annotation handlers configured in pom.xml or build.gradle file.
    2. Clean and Rebuild: you could run mvn clean install or gradle 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.
    3. Check IDE Settings: ensure that VSCode you’re using isn’t configured to run additional code generation steps that might conflict with Maven or Gradle.
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search