I’ve recently realized that each time I uninstall and reinstall the same plugin with updated logic, the old one still runs. Let’s say in the IssueUpdate event listener I have the following piece of code:
System.out.println("Hello world");
and then I change it to
System.out.println("Weird world");
I get both outputs. And if I change it further, the changes will be added to the old ones. So jira obviously caches them somewhere. But, if it caches them, why does it stop when I uninstall the plugin?
That is definitely not the normal behavior. Did you try changing the version number to see if that makes a difference? Are you uploading the plugin via UPM or running it using atlas-run?
public class Foo implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;
public Foo(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
/** Called when the plugin has been enabled */
@Override
public void afterPropertiesSet() {
eventPublisher.register(this);
}
/** Called when the plugin is being disabled or removed */
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@EventListener
public void onBlah(BlahEvent event) {
...
}
}
…and don’t forget to register the class as a component in your atlassian-plugin.xml file:
<component key="myFoo" class="com.example.Foo" />
… oh, and also import the EventPublisher component:
In fact, I don’t do this as per the documentation for the latest SDK. The spring scanner.takes care of it automatically. I use the combination of @ComponentImport and @Autowired annotations to achieve this.