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

maven-publish produces jar with source files not class files when multiple source dirs and workaround for fake duplicates #25208

Closed
carstenSpraener opened this issue May 28, 2023 · 4 comments
Labels
closed:question usage question or request for help

Comments

@carstenSpraener
Copy link

carstenSpraener commented May 28, 2023

Expected Behavior

When publishing with maven-publish the produced jar file should contain the compiled class files.

Current Behavior

The published jar file contains the sources not the class files.

Context (optional)


Gradle 8.1.1

Build time: 2023-04-21 12:31:26 UTC
Revision: 1cf537a

Kotlin: 1.8.10
Groovy: 3.0.15
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.4.1 (Eclipse Adoptium 17.0.4.1+1)
OS: Mac OS X 13.3.1 x86_64

Steps to Reproduce

Create a project with the following build.gradle

plugins {
    id 'java-library'
    id 'maven-publish'
}
group = 'my.group'
version = '0.0.1-SNAPSHOT'
sourceSets {
    src{
        main {
            java {
                srcDir('src/main/java')
                srcDir('src/main/java-gen')
            }
        }
    }
}
// WORKAROUND! If you comment this out gradle will report false duplicates
task sourcesJar(type: Jar) {
    duplicatesStrategy = 'exclude'
    from sourceSets.main.allSource
}
java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    publications {
        sonatype(MavenPublication) {
            from components.java
         }
    }
    repositories {
        maven {
            name = 'local'
            url="${project.rootDir}/repo"
        }
    }
}

Create a java File und src/main/java like:

public class Main {
}

You can leave the source folder src/main/java-gen empty.
Start publishing with:

gradle publishSonatypePublicationToLocalRepository

List the content of published jar file:

❯ jar -tf repo/my/group/PublishError/0.0.1-SNAPSHOT/PublishError-0.0.1-*-1.jar
META-INF/
META-INF/MANIFEST.MF
Main.java

Gradle version

8.1.1

Build scan URL (optional)

No response

Your Environment (optional)


Gradle 8.1.1

Build time: 2023-04-21 12:31:26 UTC
Revision: 1cf537a

Kotlin: 1.8.10
Groovy: 3.0.15
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.4.1 (Eclipse Adoptium 17.0.4.1+1)
OS: Mac OS X 13.3.1 x86_64

@carstenSpraener
Copy link
Author

Seems this bug is related to

#17236

I can't publish at the moment.

@remal
Copy link
Contributor

remal commented May 30, 2023

@carstenSpraener

First of all, your Gradle script looks a bit strange:

sourceSets {
    src{ // <-- What is it for? Are you defining `src` source set?
        main {
            java {
                srcDir('src/main/java')
                srcDir('src/main/java-gen')
            }
        }
    }
}

I suppose the issue is that you add a dir that is already added: src/main/java. By default, this dir is already presented in the main source set. So, the fix, I suppose, is to remove srcDir('src/main/java') line.

@carstenSpraener
Copy link
Author

Yepp! That's it. Many thanks. Puh! Took me nearly a day of frustration. Gradle is great again.

(By the way... maybe the srcDirs should be a set, so that double entries do not bother)

@eskatos
Copy link
Member

eskatos commented May 31, 2023

Thank you for your interest in Gradle!

Your issue appears to be a question about how to use Gradle. Your question might be answered in Gradle documentation or on our community Slack or forums. Find links to these resources on help.gradle.org.

If you think you have come across a Gradle bug, please file a new issue describing the problem and how to reproduce it.

If you think Gradle is missing a feature, please file a new issue describing your use case for the feature.


Good you sorted it out!

@eskatos eskatos closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
@eskatos eskatos added closed:question usage question or request for help and removed a:bug to-triage labels May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question usage question or request for help
Projects
None yet
Development

No branches or pull requests

3 participants