Skip to content

Commit

Permalink
First steps at making JMH Gradle plugin compatible with Gradle 4
Browse files Browse the repository at this point in the history
Note that this version would only be compatible with Gradle 4.0+ and Shadow plugin 2.0+. It makes use of the new
worker API, which avoids us doing all the nasty jar repackaging of the runtime of JMH: a worker process is automatically
spawned by Gradle with the appropriate classpath. This means that we can compile this plugin with a specific version
of JMH, but the user can override the version, and we would still use the `Main` entry point instead of an exec task
to execute the benchmarks.

This commit also fixes the [warning issued by Gradle 4.0](#94), which is the main reason for broken compatibility with
released under 4.0: the newer API doesn't exist on 3.5.

This commit however breaks a test with the shadow plugin, and is waiting for the resolution of [this bug](GradleUp/shadow#297).
  • Loading branch information
melix committed Jun 1, 2017
1 parent e417850 commit 7a64238
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 232 deletions.
26 changes: 11 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

plugins {
id 'com.gradle.build-scan' version '1.2'
id 'me.champeau.buildscan-recipes' version '0.1.3'
id 'com.gradle.build-scan' version '1.7.2'
id 'me.champeau.buildscan-recipes' version '0.2.0'
id 'com.jfrog.bintray' version '1.7.3'
id 'com.jfrog.artifactory' version '4.4.12'
id 'com.github.hierynomus.license' version '0.11.0'
Expand All @@ -31,10 +31,12 @@ buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'

publishAlways()
}

buildScanRecipes {
recipes 'git-status', 'travis-ci', 'disk-usage', 'gc-stats'
recipe 'git-commit', baseUrl: 'https://github.com/melix/jmh-gradle-plugin/tree'

publishAlways()
}

allprojects {
Expand All @@ -50,22 +52,20 @@ apply from: 'gradle/bintray.gradle'
apply from: 'gradle/artifactory.gradle'
apply from: 'gradle/code-quality.gradle'

configurations {
runner
}

dependencies {
compile localGroovy()
compile gradleApi()
compileOnly project(':runner')
testCompile project(':runner')
runner project(':runner')
compile "org.openjdk.jmh:jmh-core:$jmhVersion"
compileOnly "org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion"

testCompile "junit:junit:$junitVersion"
testCompile("org.spockframework:spock-core:$spockVersion") {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile "com.github.jengelman.gradle.plugins:shadow:$shadowVersion"

testCompile "org.openjdk.jmh:jmh-core:$jmhVersion"
testCompile "org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion"
}

task release {
Expand Down Expand Up @@ -109,8 +109,4 @@ jacocoTestReport {
}
}

jar {
from configurations.runner
}

task publishRelease(dependsOn: [bintrayUpload, publishPlugins]) {}
3 changes: 3 additions & 0 deletions gradle/compile.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

tasks.withType(JavaCompile) {
options.incremental = true
}
2 changes: 1 addition & 1 deletion gradle/funcTest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ compileFunctionalTestJava.dependsOn createClasspathManifest
task functionalTest(type: Test, dependsOn: [jar]) {
description = 'Runs the functional tests.'
group = 'verification'
testClassesDir = sourceSets.functionalTest.output.classesDir
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
mustRunAfter test

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-2-bin.zip
31 changes: 0 additions & 31 deletions runner/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion src/main/groovy/me/champeau/gradle/ExtensionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package me.champeau.gradle;

import me.champeau.jmh.runner.SerializableOptions;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.options.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2003-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,29 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.champeau.jmh.runner;
package me.champeau.gradle;

import org.gradle.api.GradleException;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import javax.inject.Inject;

public class Main {
public static void main(String[] args) throws IOException, RunnerException, ClassNotFoundException {
String optionsFile = args[0];
ObjectInputStream ois = null;
SerializableOptions options;
public class IsolatedRunner implements Runnable {

private final Options options;

@Inject
public IsolatedRunner(final Options options) {
this.options = options;
}

@Override
public void run() {
Runner runner = new Runner(options);
try {
ois = new ObjectInputStream(new FileInputStream(optionsFile));
options = (SerializableOptions) ois.readObject();
} finally {
if (ois != null) {
ois.close();
}
runner.run();
} catch (RunnerException e) {
throw new GradleException("Error during execution of benchmarks", e);
}
Runner runner = new Runner(options);
runner.run();
}
}
Loading

0 comments on commit 7a64238

Please sign in to comment.