Skip to content
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

Can't find sortOrderFile in parent home #28

Closed
GoogleCodeExporter opened this issue Mar 14, 2015 · 9 comments
Closed

Can't find sortOrderFile in parent home #28

GoogleCodeExporter opened this issue Mar 14, 2015 · 9 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Specify <sortOrderFile> file in plugin configuration inside some parent POM
2. Put the specified file in the same directory as that POM
3. Run sortpom:sort on one of the children modules of this parent

What is the expected output? What do you see instead?
sortpom:sort should use the sort order specified in <sortOrderFile>. But the 
goal fails with file not found.

What version of the product are you using? On what operating system?
Apache Maven 3.2.1, Java version: 1.7.0_60, on Mac OS X.

Here is a longer description: When I put a <sortOrderFile> named 
"sortpom-order.xml" in my top-level parent home, the sortpom plugin can't find 
it when I build a child project.

In the parent POM, ~/myproject/myproject-parent/pom.xml, I specify the 
configuration for the plugin

  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>com.google.code.sortpom</groupId>
        <artifactId>maven-sortpom-plugin</artifactId>
        <version>2.3.0</version>
        <configuration>
          <sortOrderFile>sortpom-order.xml</sortOrderFile>
          ...
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...

Then, when I build one of the children separately, say 
~/myproject/myproject-parent/myproject-child1/pom.xml, the "sortpom-order.xml" 
isn't found.

  Could not find /home/glts/myproject/myproject-parent/myproject-child1/sortpom-order.xml ...

That file of course does not exist. It's in the parent directory. I think it is 
common style to put global configuration files in the top-level parent project.

Compare the behaviour of the Maven checkstyle plugin: there I can specify a 
<configLocation>my-checkstyle.xml</configLocation> in the parent POM, put that 
file in the parent home dir, and then all the children automatically have 
access to this when I run checkstyle:checkstyle on them.

Thanks!


Original issue reported on code.google.com by 676c7...@gmail.com on 28 Jun 2014 at 5:34

@GoogleCodeExporter
Copy link
Author

Hi
I has been a while since I had a custom sort order file outside the actual 
plugin, but this is how we solved it then. 

Create a maven child module that contains resources (such as sort order files, 
logging configuration or findbugs configuration etc). (see attachment)
Then refer to the module in your sortpom plugin configuration (at top level).
        <plugin>
          <groupId>com.google.code.sortpom</groupId>
          <artifactId>maven-sortpom-plugin</artifactId>
          <version>0.2.3</version>
          <configuration>
            <createBackupFile>false</createBackupFile>
            <encoding>${project.build.sourceEncoding}</encoding>
            <sortOrderFile>sortpom/order.xml</sortOrderFile>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>my-project-group-id</groupId>
              <artifactId>plugin-resources</artifactId>
              <version>1.0</version>
            </dependency>
          </dependencies>
        </plugin>

In those days we had to do this for checkstyle configuration too. 

That said, I agree with you. It would be much easier to specify the 
configuration once at top level.
I can have a look at the code and see if there is a possibility to keep the 
configuration in the parent module.
Please tell me if the resource module solves your problem (at least temporary)

Original comment by bjorn.ek...@gmail.com on 30 Jun 2014 at 1:49

  • Changed state: Accepted
  • Added labels: Type-Enhancement, Priority-Low
  • Removed labels: Type-Defect, Priority-Medium

Attachments:

@GoogleCodeExporter
Copy link
Author

Hi,
yes, I tried your suggestion and it worked. So that's a fair workaround for me.
Thanks,

Original comment by 676c7...@gmail.com on 1 Jul 2014 at 7:01

@GoogleCodeExporter
Copy link
Author

I made an investigation and found out that an new instance of the plugin class 
is created for each module it traverses, but the class instance is the same.

This means that a working configuration in the top module can be saved in a 
static variable. That configuration can then be reused when traversing sub 
modules (if another configuration cannot be found). 

Potential problems:
It can mess with Maven parallel builds, but the risk is quite low.
It will probably not work at all with Maven 2, but then the plugin will just 
report that the configuration cannot be found as before.
The solution will definitely not work if a sub module is formatted directly 
from command line.

Now that I think about it, I wonder if I should save the whole configuration or 
the absolute path to the configuration in the static variable.

So what do you think?

Original comment by bjorn.ek...@gmail.com on 2 Jul 2014 at 7:25

@GoogleCodeExporter
Copy link
Author

Thanks for looking into this.

Unfortunately I currently don't have time to dig into the code :/ . All I can 
say is that from a (my) user perspective it is really undesirable to have the 
build fail hard just because of POM element sorting, whatever the root cause.

Original comment by 676c7...@gmail.com on 6 Jul 2014 at 11:49

@GoogleCodeExporter
Copy link
Author

Sorry for the delay.

I am now in the testing phase of the implementation and I reread your question. 
When you run your whole project from the top-level, does the child modules 
compile as well? 

Does your problem only occur when you compile a child module directly? 

Original comment by bjorn.ek...@gmail.com on 28 Jul 2014 at 9:54

@GoogleCodeExporter
Copy link
Author

Hey, yes, and yes, that's the problem exactly.

I can run 'mvn install' only from inside the parent module. When I run 'mvn 
install' from inside a child module, the build fails because sortpom can't find 
the sort order file (I have sortpom bound to a lifecycle phase).

Original comment by 676c7...@gmail.com on 3 Aug 2014 at 9:43

@GoogleCodeExporter
Copy link
Author

Doh!! Seems that I was busy solving the wrong problem. I will have to go back 
to the drawing board. 

I am not sure how to reach resources from a parent module while the parent 
isn't in the current build process.
You will get a update of the investigation if and when I find something.

Original comment by bjorn.ek...@gmail.com on 6 Aug 2014 at 7:43

@GoogleCodeExporter
Copy link
Author

Sorry. I have not found a way to directly access parent resources. 

I have three suggestions:
1. Separate resource module (as shown earilier)
2. Similar solution: 
http://javasplitter.blogspot.se/2011/08/sharing-configuration-files-from-maven.h
tml
3. If you can access your version control system through an URL, use that URL 
as filename in the pom. Example:           
<sortOrderFile>http://sortpom.googlecode.com/git/sorter/src/test/resources/diffo
rder/differentOrder.xml</sortOrderFile>

Regards

Original comment by bjorn.ek...@gmail.com on 10 Aug 2014 at 10:37

@GoogleCodeExporter
Copy link
Author

Original comment by bjorn.ek...@gmail.com on 15 Aug 2014 at 8:35

  • Changed state: WontFix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant