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 https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3

- Need to add org.mockito dependency to the 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

- Or, for now, simpler to add the following VM arguments:

-Xshare:off
-XX:+EnableDynamicAgentLoading
  • Loading branch information
Phillipus committed Nov 13, 2024
1 parent e9ddf2c commit de44b70
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 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
28 changes: 25 additions & 3 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@

<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>

<!-- 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 +51,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 @@ -67,7 +89,7 @@
</os>
</activation>
<properties>
<tycho.testArgLine>-XstartOnFirstThread</tycho.testArgLine>
<tycho.testArgLine>-XstartOnFirstThread ${mockito.args}</tycho.testArgLine>
</properties>
</profile>
</profiles>
Expand Down

0 comments on commit de44b70

Please sign in to comment.