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

Fix build failure source plugin #1677

Merged
merged 181 commits into from
Jul 25, 2024

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Jul 23, 2024

No description provided.

wind57 and others added 30 commits December 4, 2021 07:59
@wind57 wind57 marked this pull request as ready for review July 23, 2024 15:23
@wind57
Copy link
Contributor Author

wind57 commented Jul 23, 2024

@ryanjbaxter fixes our build failure. its a intermediate solution until I figure out exactly what causes it and why. thank you

@ryanjbaxter
Copy link
Contributor

ryanjbaxter commented Jul 23, 2024

I think actually this dependency upgrade broke things
spring-cloud/spring-cloud-build#277

I am not sure why, but I reverted the change and so far the build looks pretty good.

@wind57
Copy link
Contributor Author

wind57 commented Jul 24, 2024

well yes, that is the PR that broke things, but downgrading is not really a solution, imho. I don't know (yet) a smart way to solve this, but here is the issue:

The problem is in 3 things at the same time:

  • spring-boot-maven-plugin
  • maven itself
  • maven-source-plugin

When we want an image to be generated, we use the spring-boot-maven-plugin and our configuration is like this (simplified):

<executions>
  <execution>
	<id>build-image</id>
	<phase>package</phase>
	<goals>
		<goal>build-image</goal>
	</goals>
....

As such, when we run mvn clean install everything up to phase package runs, including the maven-source-plugin. In simpler words, it will look like this:

// this one generates the sources
maven-source-plugin:3.3.1:jar (attach-sources) > generate-sources ....

// this one builds the actual source jar, for example: spring-cloud-kubernetes-configuration-watcher-3.1.4-SNAPSHOT-sources.jar
maven-source-plugin:3.3.1:jar (attach-sources) 

// now build the image
spring-boot-maven-plugin:3.2.7:repackage

The problem here is that this spring-boot-maven-plugin requires the package phase : https://github.com/spring-projects/spring-boot/blob/c67d99f0528b57394e3575991d2458c2cdac46e4/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java#L65

And this means: run the package phase again. maven does not have a way to detect what was run before in the same build (there might one here : https://issues.apache.org/jira/browse/MNG-6566 , but its maven 4.0.0), as such starts all goals from that phase again, meaning some of the goals will run two times. This is how the boot plugin worked for a very long time.

This was not a problem until maven-source-plugin:3.3.1. Before 3.3.1 version, if the plugin would see that a source jar was already present, it would show a warning and move on. From 3.3.1 it fails, saying that : "you already have a sources jar, I'm to fail", in our case the error message is : "Presumably you have configured maven-source-plugin to execute twice in your build." which makes perfect sense.


I'm still thinking how to properly solve this, since we can't downgrade forever and it seems that all future versions will have this problem too. Of course, a proper solution has to come from spring-boot-maven-plugin, but I don't really know how that would be doable :(

@ryanjbaxter
Copy link
Contributor

Thanks for the investigation here. I agree that eventually we want to upgrade, but there isn't much harm in staying where we are for now and IMO is preferable to making the changes to work around the issue in this PR.

I think it is worth opening an issue with Spring Boot with the details above and see if they have some thoughts on this. My guess is that we are not the only ones running into this and maybe they have some suggestions.

@wind57
Copy link
Contributor Author

wind57 commented Jul 24, 2024

done: spring-projects/spring-boot#41601

@wind57
Copy link
Contributor Author

wind57 commented Jul 24, 2024

you were right Ryan, it was us who were configuring things incorrectly... To properly fix this, you will have to upgrade in the commons and I will fix it here. wdyt?

@ryanjbaxter
Copy link
Contributor

I merged the change in spring cloud build, once the build finishes and the snapshots are available you can test things out. It should only take a few minutes for the build to finish

@@ -18,7 +18,7 @@ you must name the image with the same name as the module. For example:
</configuration>
<phase>package</phase>
<goals>
<goal>build-image</goal>
<goal>build-image-no-fork</goal>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual fix

@@ -59,40 +59,6 @@
</dependency>
</dependencies>

<build>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the plugin from children and placed it in the parent pom, but the fix is the same

@wind57
Copy link
Contributor Author

wind57 commented Jul 24, 2024

Nice. Good to go!

@ryanjbaxter ryanjbaxter merged commit e298bb6 into spring-cloud:main Jul 25, 2024
13 checks passed
@ryanjbaxter ryanjbaxter added this to the 3.1.4 milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants