jbosstools / m2e-apt

Maven integration with Eclipse JDT Annotation Processor Toolkit
39 stars 19 forks source link

Eclipse 2020-09: broken plugin #75

Closed lrozenblyum closed 2 years ago

lrozenblyum commented 3 years ago

The m2e-apt 1.5.2 doesn't work in Eclipse 2020-09

The code that depends on annotation processing which could compile in 2020-03, stops compiling in 2020-09.

Not sure if that's related to the problem, but Eclipse log contains the exceptions

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2020-09-22 10:24:58.676
!MESSAGE Hibernate JPA 2 Static-Metamodel Generator 5.2.6.Final

!ENTRY org.eclipse.jdt.apt.pluggable.core 4 1 2020-09-22 10:24:58.678
!MESSAGE Unable to create instance of annotation processor org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
!STACK 0
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at org.hibernate.jpamodelgen.xml.JpaDescriptorParser.<init>(JpaDescriptorParser.java:60)
    at org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor.init(JPAMetaModelEntityProcessor.java:99)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.discoverNextProcessor(IdeAnnotationProcessorManager.java:97)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:119)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:171)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotationsInternal(Compiler.java:958)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:932)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:386)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:318)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:275)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:187)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:832)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 28 more
fbricon commented 3 years ago

It's obviously caused by Eclipse now requiring Java 11 to run, which no longer includes the javax.xml.bind module. Does it build in command line when compiling with a JDK 11? You can you try adding

<dependency>
  <groupId>jakarta.xml.bind</groupId>
  <artifactId>jakarta.xml.bind-api</artifactId>
  <version>2.3.3</version>
</dependency>

next to the hibernate modelgen dependency.

lrozenblyum commented 3 years ago

@fbricon 1) initially compilation in command line fails under JDK11. 2) compilation in command line with the dependency jakarta.xml.bind successfully generates target\generated-sources\annotations 3) Eclipse compilation still does nothing (even with the dependency above)

More details on the environment: The project itself is JDK8 based and uses it in Eclipse for compilation. Eclipse 2020-09 itself is indeed running under JDK11.

fbricon commented 3 years ago

please provide an example project that succeed in CLI, but fails in Eclipse.

lrozenblyum commented 3 years ago

@fbricon here it is: https://github.com/lrozenblyum/m2e-apt-eclipse-2020-09-bug

fbricon commented 3 years ago

Everything works with this pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.leokom</groupId>
    <artifactId>m2e-apt-eclipse-2020-09-bug</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <hibernate-c3p0.version>5.2.6.Final</hibernate-c3p0.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java-version>1.8</java-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate-c3p0.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-jpamodelgen</artifactId>
                            <version>${hibernate-c3p0.version}</version>
                        </path>
                        <path>
                            <groupId>jakarta.xml.bind</groupId>
                            <artifactId>jakarta.xml.bind-api</artifactId>
                            <version>2.3.3</version>
                        </path>
                        <path>
                            <groupId>javax.annotation</groupId>
                            <artifactId>jsr250-api</artifactId>
                            <version>1.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Eclipse specific: activate automatically when m2e plugin is installed -->
            <id>m2e</id>
            <activation>
                <property>
                    <name>m2e.version</name>
                </property>
            </activation>
            <properties>
                <!-- Set "Maven Integration for Eclipse JDT APT" plugin option automatically 
                    run annotation processors within the incremental compilation -->
                <m2e.apt.activation>jdt_apt</m2e.apt.activation>
            </properties>
        </profile>
    </profiles>
</project>
lrozenblyum commented 3 years ago

Thank you @fbricon! Maybe it's a nice idea to extend some part of m2e-apt documentation to mention this code that helps resolving running under Eclipse 2020-09 (it's unexpected that IDE JDK11 affects the application code running under JDK8).

fbricon commented 3 years ago

@lrozenblyum feel free to open a PR to improve the documentation. Else I'll come back to it later (no ETA)

lrozenblyum commented 3 years ago

@fbricon done, please check the pull request, remarks are welcome