-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running formatter:format goal in a multimodule project skips all submodules #261
Comments
I was able to confirm in another project that this in fact does fail to properly run when issued directory as indicated here. If I run with normal build cycle, formatter works fine in all modules. In my example I have 22 modules that nest pretty deep in some cases. @hea3ven Thanks for the report. What I would suggest though is just integrating this into your build. Once you have done so, its not a significant step and doesn't cause much hassle. The biggest problem of being integrated is that it exposes developers ability to write code without running a full build, commit that to the repo, and move on. We are trying to resolve that as well so it just always formats but there are memory leaks that are currently preventing it being turned on in IDE such as m2e integration. |
@hea3ven I highly recommend reading more about Maven lifecycles and plugin execution at: Maven – Introduction to the Build Lifecycle |
Clean does not work since that is not the cycle this is in. Compile does. This still seems weird solution. Most other plugins I've always seen just run the plugin name. Is this something we can enhance? |
@hazendaz I didn't think it would matter which lifecycle the plugin normally executes in, since the plugin is being executed directly, and not part of a lifecycle. What matters is that the reactor build plan has been set up to execute the specified lifecycles/goals, and both the clean and default lifecycles should prepare a reactor build. So, I'm not sure why the clean lifecycle wouldn't work, but I haven't tested it. I strongly suspect the reason this isn't working as expected, is because we've explicitly said it does not need to be executed in a project-context with If I am right, then executing |
Yes |
The other thing it could be is that there's no standard @Parameter(defaultValue = "${project}", readonly = true)
protected MavenProject project;
@Parameter(defaultValue = "${plugin}", readonly = true)
protected PluginDescriptor plugin; Honestly, I hope the latter fixes the problem, because it's quite convenient to execute outside of a project, and if we don't have to give that up, that's better. |
@ctubbsii What does it mean to execute outside of a project? I don't understand that. I tested 'requires_project = true', that fixes the issue entirely. |
Executing outside of a project means Maven is used to resolve plugin dependencies and execute the plugin code, but it can be executed from any directory, not just one containing a valid pom.xml file. This would be useful, for example, if you wanted to do a one-time format of code in an ant project. It's also used by things like the jetty maven plugin, to run a jetty server which serves a war, but not as part of any project. It's mostly used for executing services or to validate or transform a project without actually parsing that project. For example, you can use the eclipse maven plugin to materialize a blank eclipse project from the air. This might be how Maven archetypes work, too. |
Ah so this all makes sense now. Sort of wish maven handled both appropriately. But now I understand why it did nothing for user here. Internally we are telling it the source package locations. So if it doesn't have src/main/java and same on test side, it won't actually format anything as indicated and that would be expected given how that actually works. I'm not sure if the way it is possible to run is actually used as I've never heard or seen any feedback on that ability. If we simply flip it to require a project, issue solved here but no clue on impact. Maybe another mojo potential is possible for that type of feature to run in non maven projects? |
I've been kind of wanting to try adding the snippet above to add the MavenProject variable, rather than making the requiresProject true, just to see if that would work. My theory is that it might create a sort of "soft" dependency on the project, triggering Maven to resolve the project if it is run within a project. I'm not actually sure, though, since I've been hit with some sort of seasonal illness and haven't been feeling well enough to try it out. If that doesn't work, and it's kind of a long shot anyway, then I think we should just make it require the project. If there's a use case for running it outside of a project, we can create a separate Mojo with a different name for that. |
Thanks for the feedback. I tried both options and injecting the Maven project into the mojo didn't seem to do anything. But setting requiresProject did make it work as expected:
I think having the project-less formatting in a separate command would be useful to publicize the feature, otherwise, I don't know how anyone would have known this feature existed. |
I think setting requiresProject = true would be good for this mojo. Another mojo could be called "format-directory" with requiresProject = false, and with fewer assumptions about which directories are being formatted (src/main/*), more required parameters for non-project executions. |
Setting |
I couldn't make this work even with Can someone confirm they can make this work with the workaround? |
@victornoel I suspect there's something else going on in your project. Do you have an example project which demonstrates the problem? |
@ctubbsii you right: I didn't add the |
Ah yes. That's another way to make it behave as though it's not part of a project build. If we set require project to true, then it probably would have worked the way you expected. |
I was able to get the workaround |
You could put the validation in a profile, which is active normally (based on presence of |
@ctubbsii thanks I'll give that a try. I've noticed something as well. When
|
@bryceChernecki That sounds like an entirely new issue. Can you create an example project which demonstrates this bug, so I can take a look? |
Hey guys, whats up with this one? I have the same problem. I'm trying to setup formatting for a large multi module project. The plugin is configured to validate the formatting in phase Here is a sample project that demonstrates the problem: https://github.com/schuettec/multimodule-formatter My thoughts about the discussion above: I think the plugin should work with multi module support. If there is a requirement to provide a plugin that is working outside a project, it should be a separate Mojo. |
I doubt the path element for the formatter location actually works as you are expecting it to. I use this on lots of multimodule projects without issue. Instead add the formatter to each module location or add it to a jar.
Get Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: Christopher Schütte <[email protected]>
Sent: Tuesday, April 10, 2018 3:39:39 AM
To: revelc/formatter-maven-plugin
Cc: Jeremy Landis; Mention
Subject: Re: [revelc/formatter-maven-plugin] Running formatter:format goal in a multimodule project skips all submodules (#261)
Hey guys, whats up with this one?
I have the same problem. I'm trying to setup formatting for a large multi module project. The plugin is configured to validate the formatting in phase validate. When the formatting rules are violated I want to trigger the format goal on the parent module and I would expect the child modules to be formatted, but an mvn formatter:format only triggers the formatting for the parent module.
Here is a sample project that demonstrates the problem: https://github.com/schuettec/multimodule-formatter
My thoughts about the discussion above: I think the plugin should work with multi module support. If there is a requirement to provide a plugin that is working without outside aproject, it should be a separate Mojo.
A Maven plugin should work in a Maven project and support all basic features like multi-modules in the first place. If there is a chance to reuse a plugin feature in a non-Maven situation, this should be separated. Otherwise your are about to implement a Maven plugin that does not support Maven Projects but works for non-Maven uses cases,....which is weird ¯_(ツ)_/¯
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#261 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AA7ho76ln135ZCHipSIqYvTEsh3lS55lks5tnGG7gaJpZM4QqAUI>.
|
Have you tried the example project? It works. My last checks also made me believe that it picks the correct formatter. I don't want those |
@schuettec |
I understand this as the an explanation of why the plugin is not executed within a lifecycle.
What's the reason for not applying this mentioned fix here? The command |
Doing this will prevent other valid use cases, so it's not been my highest priority, personally, especially since it's not that hard to force it into a build lifecycle with a profile if the command line workaround doesn't work for whatever reason.
If I were you, I would bind |
I've been trying to configure the formatter plugin for a multimodule project, the thing is that I don't want to integrate it to the project's lifecycle, I just want to be able to run it manually. The problem is that when I run
mvn formatter:format
, all the submodules are skipped and no formatting is done, if I instead run the goal in a specific projectmvn -pl <submodule id> formatter:format
, it works correctly.I've tried with a minimal project both, configuring formatter-maven-plugin in the parent pom, and configuring it in the children: formatter-in-multimodule-project.zip, with the following output:
The parent pom looks like this:
The text was updated successfully, but these errors were encountered: