Manage Apps failed to delete old plugin JAR

I’m developing a plugin with Atlassian Plugin SDK. On the SDK instance, hot deploy is working perfectly.

But if I try to upload the JAR file to a standalone Jira instance, once in a while it will fail to install it.

The log shows this exception, Jira is unable to delete the plugin JAR file:

Caused by: com.atlassian.plugin.PluginException: Unable to delete plugin file: C:\Program Files\Atlassian\Application Data\Jira\plugins\installed-plugins\plugin_10926289645992153076_ConfigMigration-1.0.0.jar
	at com.atlassian.plugin.loaders.DirectoryScanner.remove(DirectoryScanner.java:177)
	at com.atlassian.plugin.loaders.ScanningPluginLoader.deleteDeploymentUnit(ScanningPluginLoader.java:214)
	at com.atlassian.plugin.loaders.ScanningPluginLoader.removePlugin(ScanningPluginLoader.java:193)
	at com.atlassian.plugin.loaders.ForwardingPluginLoader.removePlugin(ForwardingPluginLoader.java:50)
	at com.atlassian.plugin.loaders.PermissionCheckingPluginLoader.removePlugin(PermissionCheckingPluginLoader.java:37)
	at com.atlassian.plugin.manager.DefaultPluginManager.lambda$unloadPlugin$21(DefaultPluginManager.java:1054)
	at com.atlassian.plugin.manager.PluginTransactionContext.wrap(PluginTransactionContext.java:63)
	at com.atlassian.plugin.manager.DefaultPluginManager.unloadPlugin(DefaultPluginManager.java:1045)
	at com.atlassian.plugin.manager.DefaultPluginManager.uninstallNoEvent(DefaultPluginManager.java:1008)
	at com.atlassian.plugin.manager.DefaultPluginManager.lambda$updatePlugin$26(DefaultPluginManager.java:1387)
	at com.atlassian.plugin.manager.PluginTransactionContext.wrap(PluginTransactionContext.java:63)
	at com.atlassian.plugin.manager.DefaultPluginManager.updatePlugin(DefaultPluginManager.java:1365)
	at com.atlassian.plugin.manager.DefaultPluginManager.lambda$addPlugins$22(DefaultPluginManager.java:1156)
	... 90 more

The plugin folder contains two JAR files, the older one is locked by Jira server itself and cannot be deleted:



The only way to resolve it is to stop Jira, delete the old JAR, and restart.

There are no other stacktraces in the log… nothing to indicate my plugin has failed to unload or anything like that.

Why is this happening and how can I prevent it from happening? I don’t want this to happen if I’m updating plugins on a production server.

I think it is the Manage Apps page trying to load all the plugins to get their information. If I wait for the page to finish loading, then the JAR file will be unlocked.