Maven extension is cached
Answered
Hi!
we are using maven extension for resolving dependencies versions, we specify internal mechanism that checks if version of our extension defined in .mvn/extensions.xml and bom version specified in project pom.xml files are same (to ensure compatibility of dependencies versions). Unfortunately we face some problem that Intellij is caching .mvn/extensions.xml after we change branches and mechanism checking extension and bom version i failure. The problem occurs only using Intellij maven tool view. Can someone tell me why this is happening? or how can we achieve excluding .mvn/extensions.xml file from being cached by Intellij ?
Thanks.
Please sign in to leave a comment.
Hello!
Thank you for reporting this!
Could you please share more details about the issue: which extension(s) are you using, what triggers the error message (running a build, Syncing the Project, etc.) and the exact error message you are getting.
As a workaround make sure you are running Maven Sync ("Reload All Maven Project") after switching branches.
We develop and use our own extension, building this extension jar we also package versions of dependencies and plugins to properties file which is used during version resolving. This extensions is build around java class extending AbstractMavenLifecycleParticipant and logic inside of the afterProjectsRead method. In this method we extend project from session and replace plugin placeholders with proper versions from properties file, we checking if processed project bom version is same as the extension version to ensure that the most recent versions are used. If versions are different we throw an exception with bom version after read from the project and the extension version. We face the caching problem using after checkout maven reload project as well as using reload all maven projects from tool view. The error message is our own and probably won't help much here, but it clearly shows that Intellij runs the previous/old extension because the version of the extension is clearly previous branch version.
Thank you for sharing the details!
Can you please try restarting IDEA after switching the branch and let me know if it has any effect on the issue?
Restarting IDE, invalidate caches or doing any changes in maven configuration (Build, Execution, Deployment → Build Tools → Maven) will effect loading a correct extension. But in some projects its involving additional effort to restart apps after restart. And we are wondering if it's any solution to invoke refresh this file by Intellij in programatically way or by some tool view.
Thank you for the update!
Does your extension employ caching at any capacity (i. e. caching Project's objects/structure or caching Maven state/components)?
If you could share more details such as your extension's workflow, the exception you are getting, etc. - that would also be a big help for the investigation!
Thanks for your involvement in the topic!
Our extension is a module of our bom project, where we define all version of dependencies and plugins as properties values.
Extensions file placed in each project we want to use it .mvn/extensions.xml
bom: pom.xml
We save all properties to file dependency.properties (including all extension properties and parent bom project properties), which will be used during version resolution by this extension.
dependency-properties-maven-extension: pom.xml
Also, in our extension, we define a system-build.properties file like this.
And use this file as well during validating the compatibility of the extension version and the bom version from the processed project.
Our extension code is:
And the body of the method validateBomVersion which is responsible for checking bom and extension version are the same.
So when the problem occurs we face this "Differ versions of bom.version=" + rootProjectBomVersion + " and extension.xml=" + extensionVersion" message with current bom version with place of rootProjectBomVersion and the previous (version from branch from which we checkouted, old) extension version.
We also check the functionality of this extension in the pure meven project, only this extension, the bom version and some dependency/plugins (that have nothing with any caching mechanism at all).
Also, we found that the problem can occur when we modify manually version of this extension in file .mvn/extensions.xml, we're expecting that Intellij will notice the version has change and will load new proper extension dependency-properties-maven-extension, but we saw that this mechanism not throwing the error that we were expecting (bom version is differ then extension version validateBomVersion method if statement logic).
If some of those are not clear just give a hint and I will try to explain a more concise way.
Tmloszczyk Thank you for sharing the details!
I've reached out to the developers and we have been able to confirm the issue.
It appears that the state of extension is being cached by the Maven proxy-process that IDEA uses to work with Maven Projects.
As of right now, the only way to get around this issue is to stop said proxy process - for instance, by restarting IDEA or killing the process on OS level.
I have created YouTrack Issue IDEA-356061 for this issue, please keep an eye on it for further updates.