How to solve CompletionFailure when using EclipseLink Modelgen processor and Spring Security?

I am trying to use Spring Security on a project where I am using eclipselink as a modelgen processor to create a static metamodel. When I try to do this I get weird compilation errors like:

> java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.springframework.security.ldap.DefaultSpringSecurityContextSource not found

      

although I am not using LDAP. If I add jars, I get other errors like no sl4j, no openid, etc. Etc. If I swap the used model processor with the hibernate implementation, everything compiles without issue.

I found a minimal project to reproduce the problem:

MyEnity.java

@Entity
public class MyEntity {

    private String name;
    private Long id;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}

      

SecurityConfig.java

public class SecurityConfig extends WebSecurityConfigurerAdapter {

}

      

build.gradle

apply plugin: 'war'
apply plugin: 'maven'

group = 'com.demo'
version = 'alpha'

sourceCompatibility = 1.8
targetCompatibility = 1.8

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://download.eclipse.org/rt/eclipselink/maven.repo/" }
}


dependencies {
    compile 'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:2.6.0'//latest stable @06.07.2015


    compile "org.springframework:spring-beans:4.1.6.RELEASE"
    compile "org.springframework:spring-core:4.1.6.RELEASE"
    compile "org.springframework:spring-web:4.1.6.RELEASE"
    compile "org.springframework:spring-context:4.1.6.RELEASE"
    compile 'org.springframework:spring-jdbc:4.1.6.RELEASE'
    compile 'org.springframework.security:spring-security-core:4.0.2.RELEASE'
    compile 'org.springframework.security:spring-security-web:4.0.2.RELEASE'
    compile 'org.springframework.security:spring-security-config:4.0.2.RELEASE'

    providedCompile 'javax:javaee-api:7.0@jar'
}

      

As soon as I remove

a) @Entity from MyEntity

or

b) extends WebSecurityConfigurerAdapter from security config

or

c) use compile 'org.hibernate:hibernate-jpamodelgen:4.3.10.Final'

insteadcompile 'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:2.6.0'

everything compiles without issue.

So why does using the eclipselink modelgen processor cause compilation errors?

+4


source to share


1 answer


The problem is with CanonicalModelProcessor

the EclipseLink model, even in 2.7.4. It works as a Java agent, handling all classes on the classpath. At some point it ends up in a Spring Security class (for example, HttpSecurity

in my case), which has an indirect dependency on a library not found in the classpath (usually an inner class or factory return type, since Spring is designed fine. OpenIDLoginConfigurer

returned HttpSecurity.openidLogin()

refers to OpenIDAttribute

etc in my case) - at this point the whole agent crashes instead of skipping the type.

The problem is not specific to Spring or Spring Security, but any project using optional dependencies is missing from the classpath!



Surprisingly, it seems to work using OpenJDK 11, but not using OpenJDK 8. CanonicalModelProcessor

Contains bugs from my point of view . At the end, I added the generated metamodel to our project repository and dropped the modelgen for now.

UPDATE: I know this is not a real answer (unless you can go to OpenJDK 11), but at least I wanted to clarify that this is an EclipseLink bug with no workaround (as far as I know).

0


source







All Articles