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

Error when a dependency is a POM-packaging module #5349

Closed
reckart opened this issue Aug 19, 2022 · 2 comments · Fixed by #5351
Closed

Error when a dependency is a POM-packaging module #5349

reckart opened this issue Aug 19, 2022 · 2 comments · Fixed by #5351

Comments

@reckart
Copy link
Contributor

reckart commented Aug 19, 2022

I am experiencing an issue when building in Eclipse / m2e that apparently a "pom" file ends up on the classpath and this breaks the bnd-maven-plugin. The "pom" belongs to a module with "pom" packaging that is included transitively through a test dependency. The "pom.xml" belongs to a module with packaging "jar" - but it does not really include any code. Changing the packaging of that module to "pom" seems to resolve the issue.

As far as I can see, the code that collects the buildpath in AbstractBndMavenPlugin goes through all the runtime artifacts and adds them to the buildpath. This code also seems to check if an artifact is actually a JAR/ZIP ... no idea how the "pom.xml" slips through...

Stack trace:

bnd error: The JAR/ZIP file ([...]/pom.xml) seems corrupted, error: zip END header not found (biz.aQute.bnd:bnd-maven-plugin:6.3.1:test-jar:bnd-test-jar:package)

org.apache.maven.plugin.MojoExecutionException: bnd error: The JAR/ZIP file ([...]/pom.xml) seems corrupted, error: zip END header not found
	at aQute.bnd.maven.plugin.AbstractBndMavenPlugin.execute(AbstractBndMavenPlugin.java:533)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:336)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.lambda$8(MavenImpl.java:1423)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:182)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:117)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1422)
	at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:55)
	at bndtools.m2e.BndConfigurator$1.build(BndConfigurator.java:151)
	at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:135)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:169)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.lambda$1(MavenBuilder.java:114)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:182)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:117)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.lambda$0(MavenBuilder.java:105)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:182)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:156)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:103)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:88)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:198)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1024)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:254)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:311)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:400)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:403)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:514)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:462)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:544)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:161)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:255)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.util.zip.ZipException: The JAR/ZIP file ([...]/pom.xml) seems corrupted, error: zip END header not found
	at aQute.bnd.osgi.Jar.buildFromZip(Jar.java:312)
	at aQute.bnd.osgi.Jar.<init>(Jar.java:139)
	at aQute.bnd.osgi.Jar.<init>(Jar.java:237)
	at aQute.bnd.osgi.Analyzer.addClasspath(Analyzer.java:2560)
	at aQute.bnd.osgi.Analyzer.setClasspath(Analyzer.java:1680)
	at aQute.bnd.maven.plugin.AbstractBndMavenPlugin.execute(AbstractBndMavenPlugin.java:493)
	... 33 more
Caused by: java.util.zip.ZipException: zip END header not found
	at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1585)
	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1439)
	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1448)
	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1249)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1211)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:701)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:240)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:171)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:185)
	at aQute.bnd.osgi.Jar.buildFromZip(Jar.java:301)
	... 38 more

bnd: 6.3.1

@bjhargrave
Copy link
Member

There is something odd here. We already have code which confirms the file is a valid zip.

if (!artifact.getType()
.equals("jar")) {
/*
* Check if it is a valid zip file. We don't create a
* Jar object here because we want to avoid the cost of
* creating the Jar object if we decide not to build.
*/
try (ZipFile zip = new ZipFile(cpe)) {
zip.entries();
} catch (ZipException e) {
logger.debug("dependency {} is not a zip", cpe);
continue;
}
}

Can you please provide a small github repo which demonstrates the problem? Then we can investigate. Thanks.

bjhargrave added a commit to bjhargrave/bnd that referenced this issue Aug 19, 2022
Since we care about the file and not just the artifact object, we check
the file name for ending in ".jar" (jar extension) instead of relying
on the artifact reporting the "jar" type.

Fixes bndtools#5349

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@bjhargrave
Copy link
Member

I made a small change in #5351 which may address this.

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

Successfully merging a pull request may close this issue.

2 participants