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

JENKINS-70032 : Make maven-plugin an optional dependency #244

Merged
merged 2 commits into from
May 29, 2023

Conversation

aah9
Copy link

@aah9 aah9 commented Apr 4, 2023

This change makes maven-plugin an optional dependency, for the reasons explained in JENKINS-70032.

The copy artifact plugin already does this, so I just copied its plugin checks:

https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java#L525

https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java#L848

cc @alecharp since you last committed to the repo.

@aah9
Copy link
Author

aah9 commented Apr 10, 2023

@alecharp - could you review this or point me to someone that could review this, please?

Copy link
Member

@alecharp alecharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the test is valid.

If the maven-plugin is not installed, the object cannot be an instance of MavenModuleSetBuild. However, the class could not exists in that case.
How the plugin would behave it that case? The class couldn't be loaded and still the code would try to use it for the test.

Could you test that?

@@ -217,7 +222,7 @@ public void perform(@Nonnull Run<?, ?> dst, @Nonnull FilePath targetDir, @Nonnul

excludeFilter = env.expand(excludeFilter);

if (src instanceof MavenModuleSetBuild) {
if (isMavenPluginInstalled() && src instanceof MavenModuleSetBuild) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the plugin is not installed, can the src be an instance of MavenModelSetBuild? This seems redundant, no?

: (item instanceof MatrixProject
? FormValidation.warning(Messages.CopyArtifact_MatrixProject())
: FormValidation.ok());
if (isMavenPluginInstalled() && item instanceof MavenModuleSet) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito.

@aah9
Copy link
Author

aah9 commented Apr 27, 2023

I'm not sure the test is valid.

If the maven-plugin is not installed, the object cannot be an instance of MavenModuleSetBuild. However, the class could not exists in that case. How the plugin would behave it that case? The class couldn't be loaded and still the code would try to use it for the test.

Could you test that?

Sure, I'll retest it and confirm that the s3CopyArtifact steps works without the maven plugin.

My understanding of how this works is ...

The plugin compiles without errors because maven-plugin is still listed as a dependency, just with an additional property, optional = true.

At runtime, if the plugin is not installed, it'll exit the conditional statement before running src instanceof MavenModuleSetBuild, preventing a ClassNotFoundException.

@akrapfl
Copy link

akrapfl commented Apr 27, 2023

This article confirms the intent here.

This class can execute properly without the MavenModuleSetBuild, and the extra check appropriately short-circuits the condition BEFORE the exception.

I'd love this PR to be approved, as I don't want to bundle the maven-plugin anymore, but I'd like to continue to support the s3-plugin.

@aah9
Copy link
Author

aah9 commented Apr 27, 2023

Confirmed, the copy artifact from s3 step works:

  • in a freestyle job without maven plugin installed
  • in a maven job (with maven plugin installed, ofc)
  • in a freestyle job with maven plugin installed

@alecharp
Copy link
Member

Sorry, I was out. My question about the isMavenPluginInstalled method is that I'm not sure it is necessary to have this test. If the plugin is not installed, the src object cannot be of type MavenModuleSetBuild, yes?

@aah9
Copy link
Author

aah9 commented May 11, 2023

Sorry, I was out. My question about the isMavenPluginInstalled method is that I'm not sure it is necessary to have this test. If the plugin is not installed, the src object cannot be of type MavenModuleSetBuild, yes?

Correct, src cannot be of type MavenModuleSetBuild, but without the test, java will still try and check whether src is an instance of MavenModuleSetBuild, and since MavenModuleSetBuild does not exist, it will throw a ClassNotFoundException:

image

@alecharp
Copy link
Member

This makes sense. Thank you for taking the time to point this and test it.

@alecharp alecharp merged commit da70453 into jenkinsci:master May 29, 2023
@alecharp
Copy link
Member

alecharp commented Jun 2, 2023

@aah9 which JVM have you used to do your tests?

@aah9
Copy link
Author

aah9 commented Jun 2, 2023

@alecharp - My test jenkins instances were running jdk 11.

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

Successfully merging this pull request may close these issues.

3 participants