_skaffold-init task multimodule logic issues
See original GitHub issueThe issues with the current logic (at least in the maven plugin, gradle task might have the same issues):
- when a submodule has a different parent specified (e.g. spring boot starter pom) then our current logic fails to set the project id as the parent comes back as null in the InitMojo - this creates issues in multimodule projects (e.g. the Cloud Code java guestbook sample) because the listed projects don’t have anything in them
- I’m not sure how frequent nested modules are but currently we don’t handle those well either
- we are using the
artifactId
instead of the module name to return aproject
which is a problem as that is interpreted on the skaffold side as a directory
I won’t have time to fully implement the thing with tests and everything, but as I played around with the code this seemed to do the job altogether:
@Mojo(name = InitMojo.GOAL_NAME, requiresDependencyCollection = ResolutionScope.NONE)
public class InitMojo extends JibPluginConfiguration {
@VisibleForTesting static final String GOAL_NAME = "_skaffold-init";
@Override
public void execute() throws MojoExecutionException {
checkJibVersion();
MavenProject project = getProject();
MavenProject topLevelProject = getSession().getTopLevelProject();
if (!project.equals(topLevelProject)) {
return;
}
if (isParentProject(project)) {
Set<MavenProject> projects = collectLeafProjects(project);
for (MavenProject p : projects) {
print(p, true);
}
} else {
print(project, false);
}
}
private Set<MavenProject> collectLeafProjects(MavenProject project) {
Set<MavenProject> projects = new HashSet<>();
for (MavenProject p : project.getCollectedProjects()) {
if (isParentProject(p)) {
projects.addAll(collectLeafProjects(p));
} else {
projects.add(p);
}
}
return projects;
}
private boolean isParentProject(MavenProject project) {
return project.getPackaging().equals("pom") && project.getModules().size() > 0;
}
private void print(MavenProject project, boolean setProject) throws MojoExecutionException {
SkaffoldInitOutput skaffoldInitOutput = new SkaffoldInitOutput();
skaffoldInitOutput.setImage(getTargetImage());
if (setProject) {
skaffoldInitOutput.setProject(project.getGroupId() + ":" + project.getArtifactId());
}
System.out.println();
System.out.println("BEGIN JIB JSON");
try {
System.out.println(skaffoldInitOutput.getJsonString());
} catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Init - Skaffold
skaffold init walks your project directory and looks for any build configuration files such as Dockerfile , build.gradle/pom.xml ...
Read more >Kubernetes Development Environment with Skaffold
The purpose of these labs is to help you learn Kubernetes by solving different tasks, such as creating pods, scaling deployments, and so...
Read more >CHANGELOG.md · Whoisxiang/skaffold - Gitee.com
Highlights: skaffold init now supports Java and Python projects with Buildpacks projects; A bunch of debug improvements to skaffold debug; skaffold render can ......
Read more >How we reduced our Gradle build times by over 80%
If you're working on a multi-module project, then forcing Gradle to execute tasks in parallel is ... Convert build logic to static tasks....
Read more >Guide: Docker to Kubernetes Migration - IT Outposts
Will you have the resources to modify your application's logic if it needs to ... With the command skaffold init, a project can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@balopat @jonjohnsonjr we’ve released Jib 2.1.0, which fixes this issue.
For posterity, I’ll chime in to say my issue is now fixed.
Before
After