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

"-all" classifier dropped from published jar #860

Closed
HexagonSun opened this issue Apr 21, 2023 · 5 comments · Fixed by #904
Closed

"-all" classifier dropped from published jar #860

HexagonSun opened this issue Apr 21, 2023 · 5 comments · Fixed by #904

Comments

@HexagonSun
Copy link

When publishing a Maven artifact using Shadow 8.1.1, the "-all" classifier is dropped from the jar file.

This happens for both local publishing and to remote repositories, too.

Shadow Version

8.1.1

Gradle Version

8.1

Expected Behavior

Building using Shadow 8.1.0

  rm -rf build && rm -rf ${local-maven-repo} && gw publishToMavenLocal

produces the following artifacts:

  /Users/hexagonsun/.m2/repository/net/hexagon/sun/foo$find .
  .
  ./dev-local
  ./dev-local/foo-dev-local.pom
  ./dev-local/foo-dev-local-all.jar
  ./maven-metadata-local.xml

Actual Behavior

Building with Shadow 8.1.1

  rm -rf build && rm -rf ${local-maven-repo} && gw publishToMavenLocal

produces the following artifacts:

  /Users/hexagonsun/.m2/repository/net/hexagon/sun/foo$find .
  .
  ./dev-local
  ./dev-local/foo-dev-local.pom
  ./dev-local/foo-dev-local.jar
  ./maven-metadata-local.xml

Note that the jar is lacking the -all qualifier.

In both cases, i.e. with Shadow 8.1.0 as well as the new 8.1.1, the shadow-jar of the application's build directory correctly contains the -all classifier:

  /Users/hexagonsun/dev/foo/build$find . -iname "*.jar"
  ./libs/foo-dev-local-all.jar

Gradle Build Script(s)

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    val kotlinVersion = "1.8.20"

    application
    `maven-publish`
    kotlin("jvm") version kotlinVersion
    id("com.github.johnrengelman.shadow") version "8.1.1"
}

group = "net.hexagon.sun.foo"
version = "dev-local"

repositories {
    val mavenCentralProxyUrl: String by properties
    maven { url = uri(mavenCentralProxyUrl) }
}

dependencies {
    implementation(kotlin("stdlib"))
}

application {
    mainClass.set("net.hexagon.sun.foo.ApplicationKt")
}

tasks {
    withType<ShadowJar> {
        archiveClassifier.set("all")
    }
}

publishing {
    publications {
        create<MavenPublication>("shadow") {
            project.shadow.component(this)
        }
    }
}

Note that the line archiveClassifier.set("all") is not relevant: the same problem occurs when it is missing.

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

I don't think this is relevant, since the content is fine. Let me know if I should supply it.
The behavior can be reproduced using a default Application.kt file.

package net.hexagon.sun.foo

fun main() {
}
@HexagonSun
Copy link
Author

I've tracked this down to changes in 960617f..a6399e2 (the intermediate commits produce errors).

At a glance, I don't see any obvious things that caused the classifier do be omitted, then again I'm not familiar at all with this codebase. @Goooler the changes were made by you, do you know what could have caused this issue?

@Goooler
Copy link
Member

Goooler commented Jun 1, 2023

@HexagonSun
Copy link
Author

As far as I can tell tasks.shadowJar.orNull?.outputs?.files?.singleFile uses the file from the local build directory, which works indeed fine (as I initially stated, too).

The problem only arises when publishing to local or remote repositories. I'm guessing this means that project.shadow.component(this) is somehow involved.

jg210 added a commit to jg210/spring-experiments that referenced this issue Jan 12, 2024
@tha00
Copy link
Contributor

tha00 commented Jan 30, 2024

In 960617f, the artifact addition was changed in ShadowExtension from

publication.artifact(project.tasks.named("shadowJar"))

to

publication.artifact(archiveFile.get())

where archiveFile provides project.tasks.withType(ShadowJar).getByName("shadowJar").archiveFile.

The docs of MavenPublication#artifact give different behaviour for different input types:

  • An AbstractArchiveTask instance. Extension and classifier values are taken from the wrapped instance.
  • Anything that can be resolved to a File via the Project.file(Object) method. Extension and classifier values are interpolated from the file name.

Could it be that the classifier is not interpolated correctly from the file name?

EDIT: Indeed, the artifact returned by publication.artifact(archiveFile.get()) in ShadowExtension misses the classifier, even though it is correctly a part of the archive file name.

@Goooler
Copy link
Member

Goooler commented Feb 20, 2024

I've published the fix from #904 in my fork, you can try https://plugins.gradle.org/plugin/io.github.goooler.shadow

DanAlbert added a commit to DanAlbert/prefab that referenced this issue Feb 20, 2024
GradleUp/shadow#860 says this is a bug in
shadow 8.1.1. Revert to 8.1.0 until there's a fix available.
DanAlbert added a commit to google/prefab that referenced this issue Feb 20, 2024
GradleUp/shadow#860 says this is a bug in
shadow 8.1.1. Revert to 8.1.0 until there's a fix available.
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.

3 participants