cancel
Showing results for 
Search instead for 
Did you mean: 

JaCoCo integration with SAP Commerce 2205 / Java 17

raphaeldirksen
Explorer
0 Kudos

Hi,

we have (or had) jacoco within our our CI process, realized (more or less) in the following way as with an ant target:

	<target name="jacocoalltests" xmlns:jacoco="antlib:org.jacoco.ant">
		<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
			<classpath>
				<fileset dir="${bootstrap.lib.dir}/" includes="*jacoco*.jar" />
			</classpath>
		</taskdef>

		<jacoco:agent property="agentvmparam"
		              append="true"
		              output="file"
		              destfile="${report.dir}/jacoco.exec" />

		<ant dir="${hybris.platform.dir}" target="alltests">
			<property name="standalone.javaoptions" value="${agentvmparam} ${standalone.javaoptions}" />
		</ant>
		<ant dir="${hybris.platform.dir}" target="allwebtests">
			<property name="standalone.javaoptions" value="${agentvmparam} ${standalone.javaoptions}" />
		</ant>
	</target>

But after upgrading to the current SAP Commerce Version 2205 (which comes with Java 17) this is not working anymore, resulting in the following error:

[2022-08-19T10:17:14.829Z]  [yunitint] FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)
[2022-08-19T10:17:14.829Z]  [yunitint] Caused by: java.lang.reflect.InvocationTargetException
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2022-08-19T10:17:14.829Z]  [yunitint]  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[2022-08-19T10:17:14.829Z]  [yunitint]  at org.jacoco.agent.rt.internal_43f5073.core.runtime.InjectedClassRuntime$Lookup.defineClass(InjectedClassRuntime.java:134)
[2022-08-19T10:17:14.830Z]  [yunitint]  at org.jacoco.agent.rt.internal_43f5073.core.runtime.InjectedClassRuntime.startup(InjectedClassRuntime.java:54)
[2022-08-19T10:17:14.830Z]  [yunitint]  at org.jacoco.agent.rt.internal_43f5073.PreMain.premain(PreMain.java:53)
[2022-08-19T10:17:14.830Z]  [yunitint]  ... 6 more
[2022-08-19T10:17:14.830Z]  [yunitint] Caused by: java.lang.LinkageError: loader 'bootstrap' attempted duplicate class definition for java.lang.$JaCoCo. (java.lang.$JaCoCo is in module java.base of loader 'bootstrap')
[2022-08-19T10:17:14.830Z]  [yunitint]  at java.base/java.lang.ClassLoader.defineClass0(Native Method)
[2022-08-19T10:17:14.830Z]  [yunitint]  at java.base/java.lang.System$2.defineClass(System.java:2307)
[2022-08-19T10:17:14.830Z]  [yunitint]  at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2439)
[2022-08-19T10:17:14.830Z]  [yunitint]  at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2416)
[2022-08-19T10:17:14.830Z]  [yunitint]  at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:1843)
[2022-08-19T10:17:14.830Z]  [yunitint]  ... 13 more<br>

Is there any advice how to use jacoco with sap commerce 2205/java 17?

FYI: We are using jacoco 0.8.8, Ant 1.10.11 and SAP Commerce 2205.2 with Java 17 (sapmachine 17.0.4, but same behavior with oracle jdk).

best regards,

Raphael

devdixit
Explorer
0 Kudos

Hi raphael.dirksen ,

was your problem already solved? was it related to JDK package?

BR,

Dev

Accepted Solutions (0)

Answers (1)

Answers (1)

safin
Advisor
Advisor
0 Kudos

Hi Raphael,

The normal reason for LinkageError is that the same class is loaded by more than one class loader and being used together in the same code, for example, cast operation.

For you case, please check the classpath for JaCoCo to make sure it's only loaded by one classloader, an easy way is to use the -verbose:class option to make JVM log the information about all loaded class, which will help you understand where the class is coming from.

safin
Advisor
Advisor
0 Kudos

you can enable verbose:class just like this:

java -verbose:class