I have gradle project with multiple sophisticated JavaExec tasks and I want corresponding idea run configuration for convenience.
Is it possible to configure idea run configuration? Idea plugin or anything else?
We can get to the settings from the Gradle Tool Window, or from the usual Settings/Preferences dialog (⌘, (macOS), or Ctrl+Alt+S (Windows/Linux)) and navigating to Build, Execution, Deployment | Build Tools | Gradle. Generally these settings are fine for most projects, and don't need changing.
Made a custom task for that:
// create IDEA run configurations from Gradle JavaExec tasks
task createRunConfigurations {
def runConfigurationsDir = new File(".idea/runConfigurations")
runConfigurationsDir.mkdirs()
tasks.withType(JavaExec).each { task ->
def taskName = task.name
def mainClass = task.main
def props = task.systemProperties.collect { k, v -> "-D$k=$v" }.join(' ')
def args = task.args.join(" ")
def writer = new FileWriter(new File(runConfigurationsDir, "${taskName}.xml"))
def xml = new MarkupBuilder(writer)
xml.component(name: "ProjectRunConfigurationManager") {
configuration(default: 'false', name: taskName, type: "Application", factoryName: "Application", singleton: "true") {
option(name: 'MAIN_CLASS_NAME', value: mainClass)
option(name: 'VM_PARAMETERS', value: props)
option(name: 'PROGRAM_PARAMETERS', value: args)
option(name: 'WORKING_DIRECTORY', value: 'file://$PROJECT_DIR$')
module(name: 'module-name')
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With