Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea 13 UI Designer and automatic Gradle building

I've used the Intellij UI Designer to create forms for a project. Everything works fine when I'm building with idea as it handles compiling the forms for me, but as we recently switched to using Gradle for building it hasn't been possible to produce an executable jar file yet.

My google-fu has led me to several posts that explains that an ant script is needed to compile (eg link, link2, link3 ,and the one i ended on following: link4)

My project is a multi-module setup.

root build.gradle

subprojects {
    apply plugin: 'java'
    apply plugin: 'idea'

    repositories {
        mavenCentral()
    }
}

supproject build.gradle

apply plugin:'application'
mainClassName = "dk.OfferFileEditor.OfferFileEditorProgram"

configurations {
    antTask
}

dependencies {
    compile 'org.json:json:20140107'
    compile project(":Shared:HasOffers Api")

    //dependencies for java2c
    antTask files('../../lib/javac2-13.1.1.jar', '../../lib/asm4-all-13.1.1-idea.jar', '../../lib/forms_rt-13.1.1.jar')
    antTask group: 'org.jdom', name: 'jdom', version: '1.1'
}

task compileJava(overwrite: true, dependsOn: configurations.compile.getTaskDependencyFromProjectDependency(true, 'jar')) {
    doLast {
        println 'using java2c to compile'
        project.sourceSets.main.output.classesDir.mkdirs()
        ant.taskdef name: 'javac2', classname: 'com.intellij.ant.Javac2', classpath: configurations.antTask.asPath
        ant.javac2 srcdir: project.sourceSets.main.java.srcDirs.join(':'),
                classpath: project.sourceSets.main.compileClasspath.asPath,
                destdir: project.sourceSets.main.output.classesDir,
                source: sourceCompatibility,
                target: targetCompatibility,
                includeAntRuntime: false
    }
}

But even though the compilation is successfull, a Nullpointer exception is thrown the first time I try to access one of the fields the UI Designer created. So something is not being compiled correctly.

I'm probably missing some setting, but after unsuccesfully pouring several hours into forums and google I still haven't found any solution.

like image 451
LCE Avatar asked Jun 12 '14 13:06

LCE


2 Answers

The forms_rt library is in mavenCentral. http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22forms_rt%22

Once you have configured IntelliJ to update the SourceCode it is sufficient to just add the library to the dependencies in your build.gradle.

dependencies {
    compile 'com.intellij:forms_rt:7.0.3'
}
like image 70
sbaechler Avatar answered Sep 21 '22 20:09

sbaechler


I figured out an updated version of the gradle build workaround for a new project - https://github.com/edward3h/systray-mpd/blob/master/build.gradle Probably won't use the form designer again though.

These are the relevant parts:

repositories {
    mavenCentral()
    maven { url "https://www.jetbrains.com/intellij-repository/releases" }
    maven { url "https://jetbrains.bintray.com/intellij-third-party-dependencies" }
}

configurations {
    antTask
}

dependencies {
    implementation 'com.jetbrains.intellij.java:java-gui-forms-rt:203.7148.30'

    antTask 'com.jetbrains.intellij.java:java-compiler-ant-tasks:203.7148.30'
}

task compileJava(type: JavaCompile, overwrite: true, dependsOn: configurations.compile.getTaskDependencyFromProjectDependency(true, 'jar')) {
    doLast {
        project.sourceSets.main.output.classesDirs.each { project.mkdir(it) }
        ant.taskdef name: 'javac2', classname: 'com.intellij.ant.Javac2', classpath: configurations.antTask.asPath
        ant.javac2 srcdir: project.sourceSets.main.java.srcDirs.join(':'),
                classpath: project.sourceSets.main.compileClasspath.asPath,
                destdir: project.sourceSets.main.output.classesDirs[0],
                source: sourceCompatibility,
                target: targetCompatibility,
                includeAntRuntime: false
    }
}

The dependency versions for jetbrains libraries are found via https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html?from=jetbrains.org#using-intellij-platform-module-artifacts and https://www.jetbrains.com/intellij-repository/releases/

like image 29
Edward Harman Avatar answered Sep 18 '22 20:09

Edward Harman