Intellij Idea 13 UI Designer和自动Gradle构建

lce*_*sly 10 java ant intellij-idea gradle

我使用Intellij UI Designer为项目创建表单.当我正在处理为我编译表单时,一切正常,但是当我们最近切换到使用Gradle构建它时,还不可能生成可执行的jar文件.

我的google-fu带我去了几个帖子,解释说需要编译一个蚂蚁脚本(例如link,link2,link3,以及我在下面结束的那个:link4)

我的项目是一个多模块设置.

root build.gradle

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

    repositories {
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

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
    }
}
Run Code Online (Sandbox Code Playgroud)

但即使编译成功,我第一次尝试访问UI Designer创建的其中一个字段时,也会抛出Nullpointer异常.所以没有正确编译的东西.

我可能错过了一些设置,但是经过几个小时不成功地进入论坛和谷歌后我仍然没有找到任何解决方案.

lce*_*sly 9

所以我把它变得比需要的要复杂得多.

要使其工作,您需要更改项目中的两件事.

IDEA 13.1.5中的设置

设置 - > GUI Designer - >将GUI生成为:Java源代码

这使得IntelliJ IDEA在表单的底部添加了3种方法:

  • $$$ setupUI $$$()
  • $$$ setupUI $$$()
  • $$$ getRootComponent $$$()

如果缺少它们,请在更改设置后重新编译项目.

添加缺少的类

Intellij有一个名为forms_rt.jar的jar ,我在{IntelliJ IDEA Root}\lib中找到了我的jar .并将其重命名为" forms_rt-13.1.1.jar "

这需要在编译期间包含在项目中.如果你像我一样使用Gradle,你可以将它复制到{project root}/lib并添加一个flatfile存储库,如下所示:

repositories {
    mavenCentral()
    flatDir dirs: "${rootDir}/lib"
}
Run Code Online (Sandbox Code Playgroud)

之后,您需要将其包含在项目gradle文件中:

dependencies {
    compile name: 'forms_rt', version: '13.1.1'
}
Run Code Online (Sandbox Code Playgroud)

之后,应该可以在IntelliJ IDEA和Gradle中构建它.


Tom*_*dek 6

IntelliJ IDEA 2019.1

我发现这个问题仍然存在。现在至少以某种方式记录在案

如果您的构建操作委托给 Gradle,GUI Designer 将不会生成 Java 源代码。

所以通过禁用相应的设置

Build, Execution, Deployment | Build Tools | Gradle | Runner | Delegate IDE build/run actions to gradle

我能够成功地构建和运行该项目。请注意,我不需要上述答案中的任何其他设置或其他库。我让Generate GUI into被设置为Binary class files.


sba*_*ler 5

forms_rt库位于 mavenCentral。 http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22forms_rt%22

配置 IntelliJ 以更新 SourceCode 后,只需将库添加到build.gradle.

dependencies {
    compile 'com.intellij:forms_rt:7.0.3'
}
Run Code Online (Sandbox Code Playgroud)

  • 是的,但似乎是旧版本。intellij redist 目录中的 forms_rt 文件大小较大。但我在任何地方都找不到有关其版本的任何信息。你知道mavenCentral是否是最新的吗? (2认同)

Boe*_*rsi 5

理念2019.2

从 2019.1 更新到 2019.2 时,IntelliJ 似乎更改了设置 UI,因为Tom 提到的菜单条目不再存在。我通过设置为IntelliJ Idea
解决了这个问题。我还改用了IntelliJ Idea以避免测试时出现问题。 这两个设置都位于.Build and run using:Run tests using:
File | Settings | Build, Execution, Deployment | Build Tools | Gradle