Skip to content

Commit 5cc6708

Browse files
committed
Fix Kotlin-with-JMH issues
1 parent 7008049 commit 5cc6708

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

log4j-api-kotlin-benchmark/pom.xml

+27-14
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828

2929
<artifactId>log4j-api-kotlin-benchmark</artifactId>
3030

31+
<name>Apache Log4j Kotlin API benchmarks</name>
32+
3133
<properties>
3234
<bnd.baseline.skip>true</bnd.baseline.skip>
3335
<maven.test.skip>true</maven.test.skip>
3436
<maven.deploy.skip>true</maven.deploy.skip>
3537
<maven.install.skip>true</maven.install.skip>
3638
<spotbugs.skip>true</spotbugs.skip>
37-
<jmh.generator>default</jmh.generator>
3839
<uberjar.name>benchmarks</uberjar.name>
3940
</properties>
4041

@@ -77,19 +78,28 @@
7778
</dependencies>
7879

7980
<build>
81+
8082
<plugins>
8183

82-
<!-- Compile Kotlin sources first -->
84+
<!-- What follows is an unconventional plugin sequence to make JMH work with Kotlin.
85+
The follow logic can be summarized as follows:
86+
87+
1. Compile JMH-annotated Kotlin sources
88+
2. Using compiled (and JMH-annotated!) classes, generate JMH Java sources
89+
3. Add JMH Java sources
90+
4. Compile JMH Java sources -->
91+
92+
<!-- 1. Compile Kotlin sources -->
8393
<plugin>
8494
<groupId>org.jetbrains.kotlin</groupId>
8595
<artifactId>kotlin-maven-plugin</artifactId>
8696
<executions>
8797
<execution>
88-
<id>process-sources</id>
98+
<id>compile</id>
8999
<goals>
90100
<goal>compile</goal>
91101
</goals>
92-
<phase>generate-sources</phase>
102+
<phase>process-sources</phase>
93103
<configuration>
94104
<sourceDirs>
95105
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
@@ -99,7 +109,7 @@
99109
</executions>
100110
</plugin>
101111

102-
<!-- Invoke JMH generators to produce benchmark code -->
112+
<!-- 2. Generate JMH sources -->
103113
<plugin>
104114
<groupId>org.codehaus.mojo</groupId>
105115
<artifactId>exec-maven-plugin</artifactId>
@@ -112,45 +122,48 @@
112122
</dependencies>
113123
<executions>
114124
<execution>
125+
<id>generate-JMH-sources</id>
115126
<goals>
116127
<goal>java</goal>
117128
</goals>
118-
<phase>generate-resources</phase>
129+
<phase>process-resources</phase>
119130
<configuration>
120131
<includePluginDependencies>true</includePluginDependencies>
121132
<mainClass>org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator</mainClass>
122133
<arguments>
123-
<argument>${project.basedir}/target/classes/</argument>
124-
<argument>${project.basedir}/target/generated-sources/jmh/</argument>
125-
<argument>${project.basedir}/target/classes/</argument>
126-
<argument>${jmh.generator}</argument>
134+
<!-- `compiled-bytecode-dir`: -->
135+
<argument>${project.build.directory}/classes</argument>
136+
<!-- `output-source-dir`: -->
137+
<argument>${project.build.directory}/generated-sources/jmh</argument>
138+
<!-- `output-resource-dir`: -->
139+
<argument>${project.build.directory}/classes</argument>
127140
</arguments>
128141
</configuration>
129142
</execution>
130143
</executions>
131144
</plugin>
132145

133-
<!-- Add JMH generated code to the compile session -->
146+
<!-- 3. Add generated JMH sources to the compile session -->
134147
<plugin>
135148
<groupId>org.codehaus.mojo</groupId>
136149
<artifactId>build-helper-maven-plugin</artifactId>
137150
<executions>
138151
<execution>
139-
<id>add-source</id>
152+
<id>add-JMH-sources</id>
140153
<goals>
141154
<goal>add-source</goal>
142155
</goals>
143156
<phase>process-resources</phase>
144157
<configuration>
145158
<sources>
146-
<source>${project.basedir}/target/generated-sources/jmh</source>
159+
<source>${project.build.directory}/generated-sources/jmh</source>
147160
</sources>
148161
</configuration>
149162
</execution>
150163
</executions>
151164
</plugin>
152165

153-
<!-- Compile JMH generated code -->
166+
<!-- 4. Compile sources (incl. JMH-generated ones) -->
154167
<plugin>
155168
<groupId>org.apache.maven.plugins</groupId>
156169
<artifactId>maven-compiler-plugin</artifactId>

0 commit comments

Comments
 (0)