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:
- This is not a duplicate of How to enable hot swapping in debug mode with gradle and jetty?, I'm working with a standalone Java application, not Spring
- For the same reason, https://github.com/thomas-adriano/gradle-hot-swap does not apply, I think
- I would expect the HotSwap mechanism to detect changes in
/build/classes/
regardless of the used build tools - I added the
idea
plugin to my build.gradle, hoping it would fix any potential confusions of classpaths - When using the built-in IntelliJ-Compiler, hotswapping works as expected
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
.