pulumi / pulumi/pulumi-java

Support generating third party packages

Open
#536 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area/build kind/enhancement
Dominant language
Java
Stars
85
Forks
26
Avg merge
11h 49m
Merged PRs (30d)
22

Description

I used the following settings.gradle to try generate a third party package:

pluginManagement {
  repositories {
    maven { // The google mirror is less flaky than mavenCentral()
      url("https://maven-central.storage-download.googleapis.com/maven2/")
    }
    gradlePluginPortal()
  }
}

rootProject.name = "com.jaxxstorm.productionapp"
include("lib")

My build.gradle looks like this:

plugins {
    id("signing")
    id("java-library")
    id("maven-publish")
}

version = System.getenv("PULUMI_PRODUCTIONAPP_PROVIDER_SDK_VERSION") ?: "0.1.0";

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

compileJava {
    options.fork = true
    options.forkOptions.jvmArgs.addAll(["-Xmx4g"])
}

def gprUser = project.findProperty("gpr.user")  ?: System.getenv("GPR_USER")
def gprToken = project.findProperty("gpr.token") ?: System.getenv("GPR_TOKEN")

repositories {
    mavenLocal()
    maven { // The google mirror is less flaky than mavenCentral()
        url("https://maven-central.storage-download.googleapis.com/maven2/")
    }
    mavenCentral()

    if (gprUser) {
        repositories {
            maven {
                url = uri("https://maven.pkg.github.com/jaxxstorm/pulumi-productionapp")
                credentials {
                    username = gprUser
                    password = gprToken
                }
            }
        }
    }
}

def prerelease = version.contains("+")

def defaultPulumiJavaSdkVersion = "0.1.0";

def pulumiJavaSdkVersion = prerelease
    ? (System.getenv("PULUMI_JAVA_SDK_VERSION") ?: defaultPulumiJavaSdkVersion)
    : defaultPulumiJavaSdkVersion;

dependencies {
    implementation("com.google.code.findbugs:jsr305:3.0.2")
    api("com.google.guava:guava:30.1-jre") // FIXME: do we really want to expose this dep?
    api("com.google.code.gson:gson:2.8.6") // make sure we don't clash with grpc deps

    implementation("com.google.protobuf:protobuf-java:3.12.0") // make sure we don't clash with grpc deps
    implementation("com.google.protobuf:protobuf-java-util:3.12.0") // make sure we don't clash with grpc deps

    implementation("com.pulumi:pulumi:$pulumiJavaSdkVersion")

    def junitVersion = "5.7.2"
    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testImplementation("org.junit.jupiter:junit-jupiter-params:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
    testImplementation("org.assertj:assertj-core:3.20.2")
    testImplementation("org.mockito:mockito-core:3.12.4")
}

test {
    useJUnitPlatform()
    testLogging {
        showStandardStreams = true
        exceptionFormat = 'full'

        // set options for log level LIFECYCLE
        events = ['failed']

        info {
            events = ['failed', 'skipped']
        }

        debug {
            events = ['started', 'skipped', 'failed']
        }
    }
}

def ossrhRepoUrl = project.findProperty("ossrhRepoUrl") ?: System.getenv("OSSRH_REPO_URL")
def ossrhUsername = project.findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME")
def ossrhPassword = project.findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD")

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    classifier = 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    classifier = 'javadoc'
}

publishing {
    publications {
        gpr(MavenPublication) {
            groupId = "com.jaxxstorm"
            artifactId = "productionapp"
            version = version
            from components.java
            artifact sourcesJar
            artifact javadocJar

            pom {
                inceptionYear = "2022"
                name = "pulumi-productionapp"
                packaging = "jar"
                description = "Pulumi Production App Component"

                url = "https://github.com/jaxxstorm/pulumi-productionapp"

                scm {
                    connection = "git@github.com:jaxxstorm/pulumi-productionapp.git"
                    developerConnection = "git@github.com:jaxxstorm/pulumi-productionapp.git"
                    url = "https://github.com/jaxxstorm/pulumi-productionapp"
                }

                licenses {
                    license {
                        name = "The Apache License, Version 2.0"
                        url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
                    }
                }

                developers {
                    developer {
                        id = "jaxxstorm"
                        name = "Lee Briggs"
                        email = "contact@leebriggs.co.uk"
                    }
                }
            }
        }
    }

    if (ossrhUsername) {
        repositories {
            maven {
                name = "OSSRH"
                url = ossrhRepoUrl
                credentials {
                    username = ossrhUsername
                    password = ossrhPassword
                }
            }
       }
    } else {
        repositories {
            maven {
                name = "GitHubPackages"
                url = uri("https://maven.pkg.github.com/jaxxstorm/pulumi-productionapp")
                credentials {
                    username = gprUser
                    password = gprToken
                }
            }
        }
    }
}

javadoc {
    if (JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
    options.jFlags("-Xmx2g", "-Xms512m")
}

if (ossrhUsername) {
    def signingKeyId = project.findProperty("signingKeyId") ?: System.getenv("SIGNING_KEY_ID")
    def signingKey = project.findProperty("signingKey") ?: System.getenv("SIGNING_KEY")
    def signingPassword = project.findProperty("signingPassword") ?: System.getenv("SIGNING_PASSWORD")

    signing {
        useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
        sign publishing.publications.gpr
    }
}

However, the generated maven package tells me I need to import it as:

import com.pulumi.productionapp.Deployment;
import com.pulumi.productionapp.DeploymentArgs;

Doe we not supported third party "namespaces" in SDK generation?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided settings.gradle and build.gradle, then trace how the generated Maven artifact determines its Java package and imports. Compare the requested third-party package with the generated com.pulumi.productionapp namespace and establish the intended configuration; done means the supported namespace is generated consistently or the limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.