eclipse-aspectj / aspectj

Other
272 stars 82 forks source link

Throw exception for minimal AJC runtime version violation #294

Closed kriegaex closed 3 months ago

kriegaex commented 3 months ago

When running AJC, throw an AbortException(MINIMAL_JRE_VERSION) instead of just logging an error, if the minimal JRE version requirement is violated. Otherwise, in-process compilation would not fail due to the skipped System.exit(-1) that was used before. In-process compilation is, for example, relevant for AspectJ Maven Plugin, but also for non-forked executions of Plexus AspectJ via Maven Compiler.

I am not 100% sure that AbortException is the appropriate exception type, because it was designed for an aborted compilation process and here compilation has not even started yet, but it seems to work fine.

Relates to #269. Fixes #292. Supersedes PR #293.

SamD commented 3 months ago

This prevents the plugin from working with Java 11, is that intended ?

kriegaex commented 3 months ago

No, it does not. It protects users from strange error messages in favour of a clearer one, because as documented here, AJC requires Java 17+ during build time since 1.9.21. This is due to the Eclipse Java Compiler ECJ, which AJC is a fork of. I cannot change the fact that an upstream dependency contains Java 17 class files, just like a while ago I could not change the JDT Core team's decision to switch to Java 11. AspectJ's own code still is Java 8 compliant, which you will notice when running aspect-enhanced programs on Java 8 or using the load-time weaver on Java 8. But ECJ (JDT Core) is Java 17, and we need that for compile-time weaving.

For more technical details, please read https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1736540176.

SamD commented 3 months ago

Thanks for the clarification the project I'm working with is using compile-time weaving and not yet able to jump to 17. So until that time we will just need to pin aspectjtools to the previous version

kriegaex commented 3 months ago

Like I said, the Java 17 requirement only applies to the build environment. You can still run your aspects on older JREs. If you think you cannot run your build on JDK 17+ and do not need the latest AspectJ features and bugfixes, then pinning aspectjtools is a possible solution.