Gradle + IntelliJ: HotSwap in a plain Java application
Asked Answered
M

1

7

For a plain Java/Swing application, I am currently migrating the ant buildscripts to a gradle build.

While I got it up and running quickly, changes in recompiled classes are no longer picked up while debugging in IntelliJ IDEA.

All my build/run actions are delegated to gradle.

Things I've considered:

So I put together this MVCE to illustrate my problem:

build.gradle:

group 'hotswaptest'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8

src/main/java/HotSwappingOrNot.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class HotSwappingOrNot {
    public static void main(String[] args) {

        JFrame asdf = new JFrame();
        asdf.setContentPane(new JLabel("asdf"));

        asdf.setVisible(true);

        asdf.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                float r = (float) Math.random();
                Color c = new Color(r, 1-r, r);
                asdf.setBackground(c);
            }
        });
    }
}

In order to test hotswapping, I change the new Color(r, 1-r, r) -bit to new Color(r, r, r) and press Ctrl+Shift+F9.

Microbicide answered 1/12, 2017 at 9:33 Comment(0)
D
0

Not yet fixed IDEA-163187. I'm not aware of any workarounds available so far :(

Discern answered 1/12, 2017 at 10:30 Comment(4)
OK, I think I get it now -- I simply may have started out with wrong assumptions about how people combine external build tools with IDEs. Now I switched back to the built-in compiler for debug builds and only use gradle to pull dependencies and build releases.Microbicide
supposed to be fixed in upcoming IJ-2019.1Eringo
Did you figured out how to do this?Eaglestone
fixed in 2019.1Hime

© 2022 - 2024 — McMap. All rights reserved.