Skip to content

Commit

Permalink
Restore behavior of pom packaging changing the main artifact extension
Browse files Browse the repository at this point in the history
This restores the behavior before #9445 (before 5.6) and with
that fixes #10555.

The behavior for non-jar packaging is still problematic and should
be changed for 6.0 as it leads to broken Gradle Module Metadata.
  • Loading branch information
jjohannes authored and ljacomet committed Oct 14, 2019
1 parent 4579566 commit 6613982
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -133,6 +133,25 @@ class MavenPublishPomPackagingIntegTest extends AbstractMavenPublishIntegTest {
mavenModule.assertArtifactsPublished("publishTest-1.9.foo", "publishTest-1.9.pom")
}

def "can specify packaging for known jar packaging without changing artifact extension"() {
given:
createBuildScripts """
pom.packaging "ejb"
artifact("content.txt") {
extension "jar"
}
"""

when:
succeeds "publish"

then:
mavenModule.assertPublished()
mavenModule.parsedPom.packaging == 'ejb'
mavenModule.assertArtifactsPublished("publishTest-1.9.jar", "publishTest-1.9.pom")
}

def "can specify packaging with multiple unclassified artifacts"() {
given:
createBuildScripts """
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.gradle.api.publish.maven.internal.publisher;

import com.google.common.collect.ImmutableSet;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
Expand All @@ -41,11 +42,13 @@
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Set;

import static org.apache.maven.artifact.ArtifactUtils.isSnapshot;

abstract class AbstractMavenPublisher implements MavenPublisher {
private static final Logger LOGGER = LoggerFactory.getLogger(MavenPublisher.class);
private static final Set<String> JAR_PACKAGINGS = ImmutableSet.of("jar", "ejb", "bundle", "maven-plugin", "eclipse-plugin");

private static final String POM_FILE_ENCODING = "UTF-8";
private final Factory<File> temporaryDirFactory;
Expand Down Expand Up @@ -76,7 +79,9 @@ protected void publish(MavenNormalizedPublication publication, ExternalResourceR
}

if (publication.getMainArtifact() != null) {
artifactPublisher.publish(null, publication.getPackaging(), publication.getMainArtifact().getFile());
String packaging = publication.getPackaging();
String extension = packaging == null || JAR_PACKAGINGS.contains(packaging) ? publication.getMainArtifact().getExtension() : packaging;
artifactPublisher.publish(null, extension, publication.getMainArtifact().getFile());
}
artifactPublisher.publish(null, "pom", publication.getPomArtifact().getFile());
for (MavenArtifact artifact : publication.getAdditionalArtifacts()) {
Expand Down

0 comments on commit 6613982

Please sign in to comment.