Skip to content

[MNG-7045] Drop CDI API from Maven #7993

Closed

Description

@jira-importer

Romain Manni-Bucau opened MNG-7045 and commented

This is an old leak which triggered a lot of regressions and still triggers bugs in mojos.

Since there is on real justification in maven itself (@Typed is not since there are alternative and cdi is not used in any piece of maven), let's drop it.

If  a plugin needs it, it already has it since cdi-api is outdated anyway.


Remote Links:

Backported to: 4.0.0-alpha-2, 3.8.3

1 votes, 4 watchers

Activity

  1. jira-importer commented on Dec 3, 2020

    @jira-importer
    Author

    Michael Osipov commented

    Can you point to a few explicit bugs? I can't remember someone has ever reported something.

  2. jira-importer commented on Dec 3, 2020

    @jira-importer
    Author

    Mark Struberg commented

    +1 I was opposed to even the atinject and slf4j apis back then. Maven should imo be fully self-contained without any classpath conflicts.

  3. jira-importer commented on Dec 4, 2020

    @jira-importer
    Author

    Romain Manni-Bucau commented

    Michael Osipov tomee, meecrowave, weld, camel-cdi, quarkus in some context/config, exec-maven-plugin in java mode, all will fail to use CDI 2 API properly (Instance will not have stream() support for example since it was not in 1.1). Indeed upgrading to cdi-api 2.0 is a workaround in maven but since maven does NOT need this dependency and it creates issue with all implementation there is no point to try to keep it. This always had been a bug and was reported years ago, we were just too slow to fix it - blame me because I guess I was one of the first to face it. Indeed some applications not using overlapping features will run properly but this is still a bug. Also leaking API not provided is another bug (why do we export javax.enterprise and not use it at all except @Typed from memory which is not even needed. Indeed if you have another fix i'm fine with it but I think it is the simplest and less breaking fix to that old bug.

  4. jira-importer commented on Dec 4, 2020

    @jira-importer
    Author

    Michael Osipov commented

    Thank your for the explanation. Does it make sense from your POV to create an IT which shows the failure and then fixed by your change with Maven 4.0.0? That'd be awesome.

  5. jira-importer commented on Dec 4, 2020

    @jira-importer
    Author

    Romain Manni-Bucau commented

    Michael Osipov well, if it is a prerequisite to merge I'll do but it is not CDI specific, this is why Mark said maven shouldn't leak any library except org.apache.maven (or its core backbone) so it is kind of already tested with exportedpackage tests, here the configuration was just wrong. This is why I didn't add a test. Let me know if I must add one or if we are fine with our current coverage.

     

    side note: same issue applies to jsr250 but since it didnt move we don't hit it as easily ;)

  6. jira-importer commented on Dec 4, 2020

    @jira-importer
    Author

    Michael Osipov commented

    The IT is not a prerequisite. It would be nice to be able to demonstrate the failure. I am not able to create such an IT since I don't have the knowledge about the frameworks you have.
    I actually use JSR 250 in a Maven Resolver component to override a default one with {{@Priority}.
    I will leave it up to you whether you can/are able to provide an IT. I would be greatful, but won't insist.

  7. jira-importer commented on Dec 4, 2020

    @jira-importer
    Author

    Romain Manni-Bucau commented

    Ok, here is a small reproducer:

     

    <project>
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>org.apache.maven.its.mng7045</groupId>
      <artifactId>test</artifactId>
      <version>1.0</version>
    
      <name>Maven Integration Test :: MNG-7045</name>
      <description>
        Do a maven exec-java which executes some cdi 2.0 code which would fail if maven leaks cdi-api 1.0.
      </description>
    
      <dependencies>
        <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jcdi_2.0_spec</artifactId>
          <version>1.3</version>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
              <source>8</source>
              <target>8</target>
              <encoding>UTF-8</encoding>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.11.0</version>
            <executions>
              <execution>
                <id>run</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <scripts>
                <script><![CDATA[
    println("InstanceSource=" + javax.enterprise.inject.Instance.class.getProtectionDomain().getCodeSource())
    javax.enterprise.inject.Instance.class.getDeclaredMethod("stream")
              ]]></script>
              </scripts>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy</artifactId>
                <version>3.0.7</version>
                <scope>runtime</scope>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </project>

    if you run "mvn process-classes" it fails on 3.6.3 and works on 4.0.0-alpha-1-SNAPSHOT.

    The point is that as soon as you add decorator/interceptor, reflection will occur similarly to this main - this is why i dont even start a full container and just do a reflection check to ensure it uses the api specified in dependency.

    It happens for plugin using ClassRealm as parent classloader of the runtime one (so exec one can be safe in several cases but not 100%) with the default parent first strategy.

  8. jira-importer commented on Dec 22, 2020

    @jira-importer
    Author
  9. jira-importer commented on Sep 16, 2021

    @jira-importer
    Author
  10. added
    bug
    priority:major
    on Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpriority:major

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions