Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoRequires doesn't work when using mvn compiler plugin. #272

Closed
SentryMan opened this issue Feb 2, 2023 · 6 comments
Closed

AutoRequires doesn't work when using mvn compiler plugin. #272

SentryMan opened this issue Feb 2, 2023 · 6 comments
Assignees
Milestone

Comments

@SentryMan
Copy link
Collaborator

SentryMan commented Feb 2, 2023

It seems when you use inject with the compiler plugin, the ExternalProvider Serviceloader can't detect other modules.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <annotationProcessorPaths>
      <path>
        <groupId>io.avaje</groupId>
        <artifactId>avaje-inject-generator</artifactId>
        <version>${avaje.inject.version}</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>
@rbygrave
Copy link
Contributor

rbygrave commented Feb 2, 2023

huh, cause we can test that now with the extra blackbox-aspect module we have and I thought I had that configuration temporarily last night as I wanted to test how that went with java modules (module-info) and it all seemed good (I was checking that we didn't break modules when our autoProvides includes classes that were not strictly in the module-info exports ... and that was all fine. [the generated module, aspect implementation can all be internal to the module / not publically accessible to any other modules].

@rbygrave
Copy link
Contributor

rbygrave commented Feb 2, 2023

Side note, when using java modules (module-info) we need to specify annotation processors via maven-compiler-plugin ... we can't just have them as provided scope dependencies.

@SentryMan
Copy link
Collaborator Author

SentryMan commented Feb 2, 2023

blackbox-aspect module does not use the AP in the mvn compiler plugin

@rbygrave
Copy link
Contributor

rbygrave commented Feb 2, 2023

I temporarily modified both blackbox-aspect and blackbox-test-inject to use mvn compiler plugin to specify the AP ... but I ALSO at the same time changed them to use module-info.

I did that temporary to test out the module-info exports.

We could and probably should change both blackbox-aspect and blackbox-test-inject to use mvn compiler plugin to specify the AP permanently. I believe what we are saying here is that doesn't work and will reproduce this issue, so I'll try that.

@rbygrave
Copy link
Contributor

rbygrave commented Feb 6, 2023

Our fix for this with maven is to include a new avaje-inject-maven-plugin into build / plugins like:

<plugin>
  <groupId>io.avaje</groupId>
  <artifactId>avaje-inject-maven-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <phase>process-sources</phase>
      <goals>
        <goal>provides</goal>
      </goals>
    </execution>
  </executions>
</plugin>

What this does is generate 2 files in target:

  • target/avaje-module-provides.txt
  • target/avaje-plugin-provides.txt

These are the components and plugins provides by all the other modules that exist in the classpath. avaje-inject-generator then reads then at compile time and will not error if these components are required dependencies (as they are known to be provided by other modules or plugins in the classpath).

@rbygrave rbygrave added this to the 8.12 milestone Feb 6, 2023
@rbygrave
Copy link
Contributor

rbygrave commented Feb 6, 2023

Great work from @SentryMan to provide the maven plugin and work that issue through. Cheers!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants