Alexey Romanov
Alexey Romanov

Reputation: 170899

Gradle application plugin with main class in non-main source set

Documentation says

You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class. You can launch the application in debug mode with gradle run --debug-jvm (see JavaExec.setDebug(boolean)).

In my case the main class is not in the main source set but in jmh (I wanted to quickly try some things without going through the JMH infrastructure using classes defined there). Can I still use the application plugin?

Simply using ./gradlew :benchmarks:run gives "could not find or load main class MyMainClass", as expected. :jmhRun (by analogy with other tasks) gives "task 'jmhRun' not found in project 'benchmarks'". :runJmh is the same.

Upvotes: 3

Views: 585

Answers (1)

sedovav
sedovav

Reputation: 2046

It is still not possible (Gradle 5.0) as the name of the main source set is not configurable in the org.gradle.api.plugins.ApplicationPlugin#addRunTask. I've created an issue there https://github.com/gradle/gradle/issues/8113.

UPD: as was suggested in the gradle issue

tasks.named('run', JavaExec) {
    classpath = <wanted classpath>
}

Upvotes: 1

Related Questions