palantir / gradle-conjure

Gradle plugin that integrates with the Conjure toolchain
Apache License 2.0
5 stars 21 forks source link

Failing to publish Conjure Java Subprojects #1467

Open sean-hacker opened 3 months ago

sean-hacker commented 3 months ago

What happened?

Hey everyone!

I'm attempting to publish JARs from one Conjure Java project to another (trying to publish the Jersey jar as well as the Objects jar) and am struggling to get the configuration right.

My initial configuration looked like the following:

// method-server-api/build.gradle

apply plugin: 'com.palantir.conjure-publish'

configure(subprojects - project('method-server-api-typescript') - project('method-server-api-python')) {
    dependencies {
        compileOnly 'com.palantir.conjure.java:conjure-lib'
        compileOnly 'com.fasterxml.jackson.core:jackson-databind'
    }
}

configure(project('method-server-api-typescript')) {
    def ciServerHost = System.getenv('CI_SERVER_HOST')
    def ciProjectId = System.getenv('CI_PROJECT_ID')
    def ciToken = System.getenv('CI_JOB_TOKEN')

    def registryString = "https://${ciServerHost}/api/v4/projects/${ciProjectId}/packages/npm/"

    generateNpmrc.registryUri = registryString
    generateNpmrc.token = ciToken
}

conjure {
    parser {
        requireSafety = false
    }
    typescript {
        packageName = "@method-security/method-server-api"
    }
    java {
        undertowServicePrefixes = true
        useImmutableBytes = true
        jakartaPackages = true
        useStagedBuilders = true
        nonNullCollections = true
        strictObjects = true
    }
    python {}
}

serviceDependencies {}

This has been working great as I've been publishing Python packages (generating and publishing via some CI steps), but now that I want to publish the Jars, I'm struggling.

I noticed that gradle-conjure doesn't seem to add any Java packages to the publish task within gradle, even though it adds the typescript one. I saw this discussion from 2018 but it's not clear to me why gradle-conjure wouldn't provide a means to add publishing.

I attempted the following (file shortened for brevity)

apply plugin: 'com.palantir.conjure-publish'

configure(subprojects - project('method-server-api-typescript') - project('method-server-api-python')) {
    apply plugin: 'maven-publish'

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                name = "Gitlab"
                url = <Gitlab Maven URL>
                credentials {
                    username = ...
                    password = ...
                }
                authentication {
                    basic(BasicAuthentication)
                }
            }
        }
    }

    dependencies {
        compileOnly 'com.palantir.conjure.java:conjure-lib'
        compileOnly 'com.fasterxml.jackson.core:jackson-databind'
    }
}

This results in the packages being picked up by publish, but then my compileJava starts failing. From what I can tell, it seems like it's because the Undertow and Jersey projects are failing to take a dependency on the Objects project.

What did you want to happen?

It would be amazing if gradle-conjure exposed a mechanism to allow me to pipe publishing through in a clean manner, so that I can publish my Java packages.