jfrunit icon indicating copy to clipboard operation
jfrunit copied to clipboard

Build failure with JDK 17

Open danieledipompeo opened this issue 4 years ago • 6 comments

Hi guys, I got the following error while trying to build with openjdk 17 2021-09-14

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.700 s
[INFO] Finished at: 2021-11-03T16:08:42+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project jfrunit: Compilation failure
[ERROR] jfrunit/src/main/java/org/moditect/jfrunit/internal/SyncEvent.java:[26,8] cannot access jdk.internal.event.Event
[ERROR]   class file for jdk.internal.event.Event not found

I also read the #39, but I didn't understand the solution :)

Could you explain to me how to build jfr? Do I need to set some "special" configuration to my JDK?

Cheers Daniele

danieledipompeo avatar Nov 03 '21 15:11 danieledipompeo

Hey @danieledipompeo, yes, I'm observing the same when building with Java 17. JDK 16 will work, or 17, if you adjust the target release version in the POM to 17. It's not clear to me yet why this happens, building with 17 but targetting 16 should work, too. If you get to the grounds of it, any ideas would be much appreciated.

gunnarmorling avatar Nov 04 '21 21:11 gunnarmorling

That said, if you would like to send a PR for updating the target release to 17, I'd be happy to merge that. 16 doesn't make much sense anyways at this point (unmaintained). If there is an earlier version that we'd want to support, it'd be 11 (previous LTS). In order to do so, we'll need an alternative implementation though which polls on recording files instead of using JFR event streaming, which only was introduced in 14. // CC @Croway, @phejl @aalmiray

gunnarmorling avatar Nov 05 '21 07:11 gunnarmorling

Hi @gunnarmorling, @danieledipompeo, I wanted to do the same and had the same error, I think it is due to jdk.internal.event module exposure is changed in jdk17, I managed to let jfrunit build on jdk17 https://github.com/moditect/jfrunit/tree/build-jdk-17 but I'm not 100% sure this can be a solution. changes

Croway avatar Nov 05 '21 08:11 Croway

Hi @Croway, @gunnarmorling

I changed the java.release variable to 17 along with JDK17, and I got the following error Execution default of goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce failed: Unknown JDK version given. Should be something like "1.7", "8", "11", "12", "13", "14", "15", "16"

I've thought the problem was related to the unsupported JDK version on that plugin. Therefore, I've found the parent project where maven-enforcer-plugin has been defined (https://search.maven.org/artifact/org.moditect/moditect-org-parent/1.0.0.Final/pom), and I set the version.enforcer.plugin variable to the latest version (should be the 3.0.0) via CLI. However, I got the following error:

Unable to parse configuration of mojo org.apache.maven.plugins:maven-enforcer-plugin:3.0.0:enforce for parameter enforceBytecodeVersion: Cannot create instance of class org.apache.maven.plugins.enforcer.EnforceBytecodeVersion

Here, I have no idea of the next step :).

I'll try the solution by @Croway. I've also tried to set that args to the compiler, but I didn't find the right way.

BTW, I can build the project when using the JDK17 along with java.version=16.

[EDIT]

I found that the extra-enforcer-rules v1.4 should support the JDK 17. I found the following workaround to build JfrUnit with JDK17:

mvn -Djava.version=17 -Dversion.enforcer.plugin=3.0.0 -Dversion.extra.enforcer.rules=1.4 -Denforcer.skip -Dlicense.skip=true verify

and I have added this plugin definition in the jfr-aggregator pom file

<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules combine.children="override">
          <requireMavenVersion>
            <version>${maven.version}</version>
          </requireMavenVersion>
          <requireJavaVersion>
            <version>${java.version}</version>
          </requireJavaVersion>
          <enforceBytecodeVersion>
            <maxJdkVersion>${java.version}</maxJdkVersion>
          </enforceBytecodeVersion>
          <dependencyConvergence/>
          <requireUpperBoundDeps/>
        </rules>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>extra-enforcer-rules</artifactId>
      <version>${version.extra.enforcer.rules}</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</plugin>

danieledipompeo avatar Nov 05 '21 09:11 danieledipompeo

@danieledipompeo interesting, I tried it and it works, much more elegant compared to play with modules :smile: I came up with https://github.com/moditect/jfrunit/tree/add-extra-enforcer-rules-dep , too bad there are many dependency in quarkus that let the enforcer fail, that's why I had to add <fail>false</fail>, but now we can execute mvn clean install without specifying additional parameter or skip the enforcer (just ignore it :D) these are the changes. WDYT?

CC @gunnarmorling

OT, @danieledipompeo I see you are in Aquila, are you from Abruzzo? actually I'm from Pescara

Croway avatar Nov 12 '21 14:11 Croway

@Croway yes I'm from L'Aquila :)

I'll prepare the PR in the next few days,

I'll keep you posted

danieledipompeo avatar Nov 19 '21 10:11 danieledipompeo