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

Cannot get it to fail as expected #33

Open
robross0606 opened this issue Feb 15, 2022 · 13 comments
Open

Cannot get it to fail as expected #33

robross0606 opened this issue Feb 15, 2022 · 13 comments

Comments

@robross0606
Copy link

robross0606 commented Feb 15, 2022

For specific reasons, I'm trying to leverage this plugin from a straight CLI call in a maven project like this:

mvn org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true 

However, no matter what I do the build/plugin happily succeeds and never fails. The following two calls both succeed which, if I'm reading correctly, should be impossible:

mvn org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true 
mvn org.honton.chas:exists-maven-plugin:remote -Dexists.failIfNotExists=true 

I've also do this to see if properties were set, but that doesn't seem to be the case either:

mvn org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true help:effective-pom

What am I doing wrong?

@chonton
Copy link
Owner

chonton commented Feb 15, 2022

Please run mvn with '-X' option. This will enable debugging output. What values are being passed to the plugin?

@robross0606
Copy link
Author

robross0606 commented Feb 15, 2022

Based on your suggestion, I've tweaked my calls but still no luck:

mvn -X org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true -Dexists.skipIfSnapshot=false
...
[DEBUG] Configuring mojo 'org.honton.chas:exists-maven-plugin:0.6.0:remote' with basic configurator -->
[DEBUG]   (f) artifact = mock-java-shared-library-0.0.1-SNAPSHOT.jar
[DEBUG]   (f) cmpChecksum = false
[DEBUG]   (f) failIfExists = true
[DEBUG]   (f) failIfNotExists = false
[DEBUG]   (f) failIfNotMatch = true
[DEBUG]   (f) mavenProject = MavenProject: com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT @ C:\Code\mock\Bitbucket\mock-java-shared-library\pom.xml
[DEBUG]   (f) project = com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT
[DEBUG]   (f) property = maven.deploy.skip
[DEBUG]   (f) repository = https://artifact.nurocorinternal.com/repository/maven-releases
[DEBUG]   (f) serverId = com.nurocor.repo.releases
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@6f952d6c
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@5965844d
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipIfSnapshot = false
[DEBUG]   (f) snapshotRepository = https://artifact.nurocorinternal.com/repository/maven-snapshots
[DEBUG]   (f) snapshotServerId = com.nurocor.repo.snapshots
[DEBUG]   (f) userProperty = false
[DEBUG] -- end configuration --
[DEBUG] Checking for artifact at https://artifact.nurocorinternal.com/repository/maven-snapshots/com/nurocor/mock/mock-java-shared-library/0.0.1-SNAPSHOT/mock-java-shared-library-0.0.1-SNAPSHOT.jar
[DEBUG] no server configuration
[INFO] com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT does not exist

However, I know the file does exist in our Nexus repo:
image

The problem seems to be that it is checking the wrong URL for the JAR file since it is getting a timestamp attached.

@chonton
Copy link
Owner

chonton commented Feb 15, 2022

Have you configured the plugin with per-execution configuration or global confguration?

          <plugin>
            <groupId>org.honton.chas</groupId>
            <artifactId>exists-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>remote</goal>
                </goals>
                <configuration>
                  <!-- per-execution configuration -->
                </configuration>
              </execution>
            </executions>
            <configuration>
                <!-- global configuration -->
            </configuration>
          </plugin>     

@robross0606
Copy link
Author

Neither. As I said in the post, I'm making this call purely from a CLI with no POM configuration at all.

@robross0606
Copy link
Author

robross0606 commented Feb 15, 2022

Looks like this is probably a duplicate of #26.

 Checking for artifact at https://artifact.nurocorinternal.com/repository/maven-snapshots/com/nurocor/mock/mock-java-shared-library/0.0.1-SNAPSHOT/mock-java-shared-library-0.0.1-SNAPSHOT.jar

That is not the URL to the artifact.

@chonton
Copy link
Owner

chonton commented Feb 15, 2022

Probably. Snapshots are difficult to deal with. How do we determine if a particular snapshot is current? Each deploy of a snapshot creates a new timestamped suffix. What timestamp should we use? If we use latest timestamp in remote repository, what local timestamp to use?

You may wish to experiment with hash comparison instead. (Which introduces its own set of problems.)

@chonton
Copy link
Owner

chonton commented Feb 15, 2022

For your use case, perhaps knowledge that any snapshot version exists is sufficient?

@robross0606
Copy link
Author

Yes, that would be a fair statement.

@robross0606
Copy link
Author

robross0606 commented Feb 16, 2022

It also seems that you cannot override the fact that the pom version lists as a SNAPSHOT. For example, I tried this:

mvn -X build-helper:parse-version org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true -Dexists.artifact='${project.artifactId}-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.{project.packaging}'
...
[DEBUG] Configuring mojo 'org.honton.chas:exists-maven-plugin:0.6.0:remote' with basic configurator -->
[DEBUG]   (f) artifact = 'mock-java-shared-library-0.0.1.jar'
[DEBUG]   (f) cmpChecksum = false
[DEBUG]   (f) failIfExists = true
[DEBUG]   (f) failIfNotExists = false
[DEBUG]   (f) failIfNotMatch = true
[DEBUG]   (f) mavenProject = MavenProject: com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT @ C:\Code\mock\Bitbucket\mock-java-shared-library\pom.xml
[DEBUG]   (f) project = com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT
[DEBUG]   (f) property = maven.deploy.skip
[DEBUG]   (f) repository = https://artifact.nurocorinternal.com/repository/maven-releases
[DEBUG]   (f) serverId = com.nurocor.repo.releases
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@7d070ef5
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@7a55f148
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipIfSnapshot = true
[DEBUG]   (f) snapshotRepository = https://artifact.nurocorinternal.com/repository/maven-snapshots
[DEBUG]   (f) snapshotServerId = com.nurocor.repo.snapshots
[DEBUG]   (f) userProperty = false
[DEBUG] -- end configuration --
[DEBUG] skipping -SNAPSHOT

Even though my pom.xml lists the project as a SNAPSHOT, I would have expected this to check for the artifact listed in exists.artifact. Instead, it skipped because the pom.xml has a snapshot version.

I then tried adding skipIfSnapshot and this seems to get further but still do something unexpected:

mvn -X build-helper:parse-version org.honton.chas:exists-maven-plugin:remote -Dexists.failIfExists=true -Dexists.artifact='${project.artifactId}-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.${project.packaging}' -Dexists.skipIfSnapshot=true
...
[DEBUG] Configuring mojo 'org.honton.chas:exists-maven-plugin:0.6.0:remote' with basic configurator -->
[DEBUG]   (f) artifact = 'mock-java-shared-library-0.0.1.jar'
[DEBUG]   (f) cmpChecksum = false
[DEBUG]   (f) failIfExists = true
[DEBUG]   (f) failIfNotExists = false
[DEBUG]   (f) failIfNotMatch = true
[DEBUG]   (f) mavenProject = MavenProject: com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT @ C:\Code\mock\Bitbucket\mock-java-shared-library\pom.xml
[DEBUG]   (f) project = com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT
[DEBUG]   (f) property = maven.deploy.skip
[DEBUG]   (f) repository = https://artifact.nurocorinternal.com/repository/maven-releases
[DEBUG]   (f) serverId = com.nurocor.repo.releases
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@62566842
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@2f1ea80d
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipIfSnapshot = false
[DEBUG]   (f) snapshotRepository = https://artifact.nurocorinternal.com/repository/maven-snapshots
[DEBUG]   (f) snapshotServerId = com.nurocor.repo.snapshots
[DEBUG]   (f) userProperty = false
[DEBUG] -- end configuration --
[DEBUG] Checking for artifact at https://artifact.nurocorinternal.com/repository/maven-snapshots/com/nurocor/mock/mock-java-shared-library/0.0.1-SNAPSHOT/'mock-java-shared-library-0.0.1.jar'
[DEBUG] no server configuration
[INFO] com.nurocor.mock:mock-java-shared-library:0.0.1-SNAPSHOT does not exist

This looks like it used the expected artifact property for the check, but did so inside a snapshot directory. So there's not way to use this and check for a version not listed in the POM? In our particular use case, we would want to prevent someone from publishing a snapshot on a version if the release has already been published. This plugin seemed like a great way to do that, but it seems that is impossible without actively changing the POM before using the plugin.

Incidentally, your README file has a slight typo:
image
Pretty sure that should read as ${project.packaging}

@chonton
Copy link
Owner

chonton commented Feb 19, 2022

Please try version 0.7.0 to see if this satisfies your use case.

@robross0606
Copy link
Author

I'm unclear from the change log what has actually changed or how I would leverage it.

@robross0606
Copy link
Author

robross0606 commented Feb 24, 2022

I don't think 0.7.0 did much of anything to help if I'm understanding the fix. I did:

mvn -X build-helper:parse-version org.honton.chas:exists-maven-plugin:0.7.0:remote -Dexists.failIfExists=true -Dexists.artifact='${project.artifactId}-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.${project.packaging}' -Dexists.skipIfSnapshot=true
...
[DEBUG] Configuring mojo org.honton.chas:exists-maven-plugin:0.7.0:remote from plugin realm ClassRealm[plugin>org.honton.chas:exists-maven-plugin:0.7.0, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@73d16e93]
[DEBUG] Configuring mojo 'org.honton.chas:exists-maven-plugin:0.7.0:remote' with basic configurator -->
[DEBUG]   (f) artifact = 'mock-java-backend-service-0.0.1.jar'
[DEBUG]   (f) cmpChecksum = false
[DEBUG]   (f) failIfExists = true
[DEBUG]   (f) failIfNotExists = false
[DEBUG]   (f) failIfNotMatch = true
[DEBUG]   (f) mavenProject = MavenProject: com.nurocor.mock:mock-java-backend-service:0.0.1-SNAPSHOT @ C:\Code\mock\Bitbucket\mock-java-backend-service\pom.xml
[DEBUG]   (f) project = com.nurocor.mock:mock-java-backend-service:jar:0.0.1-SNAPSHOT
[DEBUG]   (f) property = maven.deploy.skip
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@2d7a9786
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@7bab5898
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipIfSnapshot = true
[DEBUG]   (f) userProperty = false
[DEBUG] -- end configuration --
[DEBUG] skipping -SNAPSHOT

This now appears to have ignored exists.artifact property entirely and only used the values in the POM. Because skipIfExists was set, it skipped the check instead of using exists.artifact. This is the opposite of what would be helpful for my use case. I effectively need to provide all the data on the command line and not use the POM at all.

It doesn't seem like this plugin is useful for my intended purpose, which seems a little odd considering the purpose is to "check if some artifact exists". The fundamental impedance mismatch is that your "artifact" property is the name of the JAR file. This is quite a bit different than standard plugins like Maven Dependency plugin. Take, for example dependency:copy (https://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html). In this plugin, artifact represents the full artifact identifier (groupId:artifactId:version[:packaging[:classifier]]), not the "JAR" file name. The JAR file name is usually constructed from those values, not the other way around. In this plugin, there is no such ability to specify the real artifact by ID. It relies on the POM for that data and then allows you to override only the name of the resulting JAR.

@chonton
Copy link
Owner

chonton commented Feb 25, 2022

Did you want exists.skipIfSnapshot to be true or false?

There does appear to be a defect in that SNAPSHOT is determined by project rather than by given exists.artifact, so I recommend trying with exists.skipIfSnapshot=false

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

No branches or pull requests

2 participants