Skip to content

Commit

Permalink
Add support for Mockito/ByteBuddy requiring javaagent on Java 21
Browse files Browse the repository at this point in the history
- See mockito/mockito#3037
- See mockito/mockito#3037 (comment)
- See https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3

- Need to add org.mockito dependency to testsupport plugin so that the path to the mockito jar is always resolved when using ${org.mockito:mockito-core:jar}

- To run JUnit in Eclipse you need to add the following VM arguments (adjust path version as required):

-Xshare:off
-javaagent:${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.mockito.mockito-core_5.14.2.jar
  • Loading branch information
Phillipus committed Nov 12, 2024
1 parent cca4be1 commit 5f995fb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: 'maven'

Expand Down
4 changes: 2 additions & 2 deletions com.archimatetool.editor.product/archi.target
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<unit id="org.eclipse.jgit.ssh.apache.feature.group" version="6.10.0.202406032230-r"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.32.0"/>
<unit id="org.mockito.mockito-core" version="5.12.0"/>
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-12"/>
<unit id="org.mockito.mockito-core" version="5.14.2"/>
</location>
</locations>
</target>
1 change: 1 addition & 0 deletions tests/com.archimatetool.testsupport/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bundle-Vendor: Archi
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Export-Package: com.archimatetool.tests
Import-Package: org.mockito
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui
Bundle-ClassPath: .
Expand Down
63 changes: 36 additions & 27 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,34 @@

<artifactId>com.archimatetool.testing</artifactId>
<packaging>pom</packaging>

<properties>
<!-- Mockito/ByeBuddy needs this on Java 21+ -->
<mockito.args>-Xshare:off -javaagent:${org.mockito:mockito-core:jar}</mockito.args>
<!-- <tycho.testArgLine> is passed as <argLine> to tycho-surefire-plugin -->
<tycho.testArgLine>${mockito.args}</tycho.testArgLine>
</properties>

<profiles>
<profile>
<id>osx</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<tycho.testArgLine>-XstartOnFirstThread ${mockito.args}</tycho.testArgLine>
</properties>
</profile>
</profiles>

<!-- Orbit p2 repo provides Mockito and latest JUnit for tests -->
<repositories>
<repository>
<id>Orbit</id>
<layout>p2</layout>
<url>https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/release/4.32.0</url>
<url>https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-12</url>
</repository>
</repositories>

Expand All @@ -43,6 +64,20 @@

<build>
<plugins>
<!-- Add this so we can resolve ${org.mockito:mockito-core:jar} -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
Expand All @@ -56,30 +91,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>osx</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<argLine>-XstartOnFirstThread</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

</project>

0 comments on commit 5f995fb

Please sign in to comment.