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

Is it normal that pom.xml in target repository is checked ? #229

Closed
sbernard31 opened this issue Jul 5, 2022 · 7 comments
Closed

Is it normal that pom.xml in target repository is checked ? #229

sbernard31 opened this issue Jul 5, 2022 · 7 comments
Labels

Comments

@sbernard31
Copy link

I use v3.0.1 because of #225

I add this to my project :

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.ekryd.sortpom</groupId>
        <artifactId>sortpom-maven-plugin</artifactId>
        <configuration>
          <createBackupFile>false</createBackupFile>
          <lineSeparator>${leshan.lineseparator}</lineSeparator>
          <verifyFail>stop</verifyFail>
          <verifyFailOn>Strict</verifyFailOn>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

When launching : mvn com.github.ekryd.sortpom:sortpom-maven-plugin:verify all seems OK
but when launching : mvn clean install

[INFO] --- sortpom-maven-plugin:3.0.1:verify (default) @ leshan-core ---
[INFO] Verifying file /home/sbernard/git/leshan/leshan-core/target/leshan-core-2.0.0-SNAPSHOT.pom
[ERROR] The line 21 is not considered sorted, should be '<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">'
[ERROR] The file /home/sbernard/git/leshan/leshan-core/target/leshan-core-2.0.0-SNAPSHOT.pom is not sorted

My explanation is that :
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:verify only check pom.xml from source directory.
but mvn clean install checks target/leshan-core-2.0.0-SNAPSHOT.pom which means build directory and not source directory.

In my case I use flatten-maven-plugin which change the pom.xml.

I would like to only check the source pom.xml file in source directory not the generated one in build directory.

Is there a way to do that or maybe I did something wrong ?

@Ekryd
Copy link
Owner

Ekryd commented Jul 5, 2022

Hi! I am busy the following days, so it will take some time before I can look at this for real. Thanks for your patience.
ps. it should be the source but but I haven’t experienced your problem. Is it possible to recreate in an integration test?

@sbernard31
Copy link
Author

I will maybe find time to create an integration test that but not sure.

Waiting you could use : sbernard31/leshan#11 to reproduce that.

@Ekryd
Copy link
Owner

Ekryd commented Jul 7, 2022

Thanks!

@sbernard31
Copy link
Author

I digged a little more about this.

Explanation about why it is called twice ?
I find why the sortpom:verify goal (attached to validate phase by default) is called twice.

This is because my build also run maven-source-plugin:jar goal which :

First try to fix it :
To attach sortpom:verify goal to process-sources, this way maven-source-plugin will execute generate-sources and will not recall it.
==> It seems to work ✔️

Second try to fix it :
Using maven-source-plugin:jar-no-fork which does not invoke `generate-sources. (more details)
==> it seems to work too ✔️

So I guess this is not a sortpom issue.

@sbernard31
Copy link
Author

Before to find this, I begin to write 1 IT test but I was not able to reproduce because in my IT test sortpom:verify was called twice but still on same file.

Even when I was using flatten-maven-plugin, the flattened pom file was created by not used by sortpom... 🤷

So a remaining question (not related to sortpom) is : why IT test and "real use case" behave differently ?

I let the IT test just in case :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.ekryd.sortpom.its</groupId>
  <artifactId>default-configuration</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>SortPom Plugin :: ITs :: Default configuration</name>
  <description>Test default parameters of the plugin</description>
  <url>no-url</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.ekryd.sortpom</groupId>
        <artifactId>sortpom-maven-plugin</artifactId>
        <version>3.1.4-SNAPSHOT</version>
        <executions>
          <execution>
            <goals>
              <goal>verify</goal>
            </goals>
            <configuration>
              <violationFilename>target/sortpom_reports/violation.xml</violationFilename>
              <verifyFail>stop</verifyFail>
              <verifyFailOn>Strict</verifyFailOn>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
        <version>1.2.7</version>
        <configuration>
          <flattenMode>ossrh</flattenMode>
          <!--  see https://github.com/mojohaus/flatten-maven-plugin/issues/53#issuecomment-388076343 -->
          <outputDirectory>${project.build.directory}</outputDirectory>
          <flattenedPomFilename>${project.artifactId}-${project.version}.pom</flattenedPomFilename>
        </configuration>
        <executions>
          <execution>
            <id>flatten</id>
            <goals>
              <goal>flatten</goal>
            </goals>
            <phase>process-resources</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

@Ekryd
Copy link
Owner

Ekryd commented Jul 7, 2022

I am glad that the problem was solved for you and thank you for posting it as an issue (in case somebody else stumbles on the same problem).
I guess that the IT test framework does some hacking in the Maven process. The IT tests themselves does not execute in the source directory, but it moves all files to the target/it directory before executing. Perhaps it also caches the pom file input instead of reading the pom between each phase??

@Ekryd Ekryd added the question label Jul 7, 2022
@sbernard31
Copy link
Author

I guess that the IT test framework does some hacking in the Maven process. The IT tests themselves does not execute in the source directory, but it moves all files to the target/it directory before executing. Perhaps it also caches the pom file input instead of reading the pom between each phase??

Probably something like this. 🤷

I guess we can close this issue ?

@Ekryd Ekryd closed this as completed Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants