Cannot use multiple sourceDirectories
jvicens19 opened this issue · comments
I have this config on my pom.xml:
..
src/main/groovy,src/main/java
...
However, only *.java files of src/main/groovy source directory are getting formatted
You have to provide me a way to reproduce the issue. A public git repository for example.
On any project with multiple sourceDirectories (src/main/java, src/main/java2)
with only first one configured and second one imported with:
org.codehaus.mojo
build-helper-maven-plugin
initialize
add-source
Executing hook with "initialize" phase before "on-pre-commit" goal would fix it because second directory is configured when "build-helper-maven-plugin" is executed . (It is the workaround we use on manual execution formating). However, I don't know how to work with precommit hook in order to ensure "hook" format on both source directories.
@jvicens19 I maintain this library on my free time. If you want me to solve the issue quickly, make my life easy by providing a git repository reproducing it.
If you can’t, don’t expect the issue to be solved soon.
@jvicens19 , as explained in #27 (comment), all plugin goals (including on-pre-commit goal) process all *.java
files provided by MavenProject#getCompileSourceRoots
and MavenProject#getTestCompileSourceRoots
.
Comment this issue with a link to a git repository demonstrating the problem if you want me to take a look at it.
Hi, I am sorry that the project that reproduces it is not sharable. I will try to reproduce it in a small project and let you see that.
Now I am going to explain better the issue:
- MavenProject#getCompileSourceRoots initially includes one source directory defined in ${project.build.sourceDirectory}
- Using multiple source directories is possible using a mvn plugin: https://www.mojohaus.org/build-helper-maven-plugin/usage.html
- That build-helper-maven-plugin runs on "initialize" maven fase. That means that MavenProject#getCompileSourceRoots is not updated with additional directories after initialize phase
- Pre commit hook runs: com.cosium.code:git-code-format-maven-plugin:on-pre-commit.
that goal "on-pre-commit" runs independently and obviously not include "inititalize" phase that would add additional directories. - Running "mvn initialize git-code-format:format-code -Dgcf.globPattern=**/*" solves the issue and do format all directories sources.
It is possible to include initialize phase on the hook *.sh to solve this issue?
@jvicens19 , when I add initialize
to the pre commit hook shell, tests fail.