Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle + Intellij idea: run configuration

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?

like image 266
Fedyanint Timofey Avatar asked Apr 29 '16 21:04

Fedyanint Timofey


People also ask

Where is Gradle settings in IntelliJ?

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.


1 Answers

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')
            }
        }
    }
}
like image 114
relgames Avatar answered Sep 29 '22 12:09

relgames