tobiasmanske.de/content/posts/2021-02-23-maven-ij-designe...

3.5 KiB

title date lastmod categories tags keywords summary showTOC
Compiling IntelliJ Designer Forms with Maven 2021-02-23T03:59:59+01:00 2021-09-20T10:58:54+02:00
software
hacking
english
software engineering
maven
intellij forms
maven
intellij gui
designer
forms
swing
compile
Ever wanted to compile IntelliJ IDEA GUI-Designer forms with maven? I've found a 2021 solution. false

Edit 09/2021: Updated the 3rdparty repository URL :)

In 2021 I worked in a small team of students on an old fashioned Java swing application. To design our forms rather fast, we chose to opt for the IJ-GUI designer.

That turned out to be a rather annoying mistake, trying to package the Software just hours before the deadline.We were unable to come up with a solution to compile the forms on our build server in that short time. So, we then opted to just let IntelliJ compile the .forms into .java directly, which then cluttered our version control.

Today I present you the fix: A minimal pom.xml compiling forms on the fly. A complete minimal working example can be found on my private git: git.tobiasmanske.de

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>de.tobiasmanske</groupId>
  <artifactId>example</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <intellij.version>203.7148.57</intellij.version>
  </properties>

  <repositories>
    <repository>
      <id>jetbrains.releases</id>
      <url>https://www.jetbrains.com/intellij-repository/releases</url>
    </repository>
    <repository>
      <id>jetbrains.3rdparty</id>
      <url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
    </repository>
  </repositories>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <configuration>
              <target>
                <path id="j2sp">
                  <pathelement location="${project.basedir}/src/main/java"/>
                </path>
                <taskdef name="javac2" classpathref="maven.runtime.classpath" classname="com.intellij.ant.Javac2"/>
                <javac2 destdir="${project.basedir}/target/classes">
                  <src refid="j2sp"/>
                </javac2>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.jetbrains.intellij.java</groupId>
      <artifactId>java-gui-forms-rt</artifactId>
      <version>${intellij.version}</version>
    </dependency>
    <dependency>
      <groupId>com.jetbrains.intellij.java</groupId>
      <artifactId>java-compiler-ant-tasks</artifactId>
      <version>${intellij.version}</version>
    </dependency>
  </dependencies>
</project>

That's all for today, I hope this helped you, so that you don't struggle with it for as long.