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

Default to using gradle-nexus in gen-sdk #1612

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

julienp
Copy link
Contributor

@julienp julienp commented Jan 30, 2025

When using pulumi-java-gen, the user can bass a —build flag to set gradle related settings in the PackageInfo:

--build PackageInfo Behaviour
none no gradle file, default
gradle buildFiles: gradle gradle file without nexus plugin
gradle-nexus buildFiles: gradle, gradleNexusPublishPluginVersion: 2.0.0 gradle file with nexus plugin, using default version of the plugin
gradle-nexus:$VER buildFiles: gradle, gradleNexusPublishPluginVersion: $VER gradle file with nexus plugin, using specified version of the plugin

Pulumi providers use --build gradle-nexus.

When using gen-sdk instead of pulumi-java-gen, you control the gradle generation with the PackageInfo. To streamline the usage of the most desired behaviour (gradle-nexus), this PR changes the behaviour of the buildFile option when using gen-sdk. The behaviour when using pulumi-java-gen is unchanged.

This allows providers to not set any options in their schema and still get the best default behaviour.

PackageInfo Behaviour
buildFiles: none no gradle file
buildFiles: gradle-nexus gradle file with nexus plugin, using default version of the plugin, 2.0.0, the default
buildFiles: gradle-nexus, gradleNexusPublishPluginVersion: $VER gradle file with nexus plugin, using version $VER of the plugin
buildFiles: gradle gradle file without nexus plugin
buildFiles: gradle, gradleNexusPublishPluginVersion: $VER gradle file with nexus plugin, using version $VER of the plugin

Fixes #1593

When using `pulumi-java-gen`, the user can bass a `—build` flag which the following options:

* `none`: no gradle file is generated (the default)
* `gradle`: a gradle file is generated -> BuildFiles: gradle
* `gradle-nexus`: a gradle file using the nexus publishing plugin is generated, using a default version of the plugin -> BuildFiles: gradle, GradleNexusPublishPluginVersion: 2.0.0
* `gradle-nexus:$VER`: a gradle file using the nexus publishing plugin is generated, using the version $VER for the plugin -> BuildFiles: gradle, GradleNexusPublishPluginVersion: $VER

Using `gen-sdk`, the options are managed via the schema, `buildFiles` can take the following options:
* `gradle-nexus`: the default if the buildFiles is not set, a gradle file using the nexus publishing plugin is generated, implies `gradleNexusPublishPluginVersion: 2.0.0` if `gradleNexusPublishPluginVersionA` is not set.
* `gradle`: a gradle file is generated, but without the nexus publishing plugin
* `none`: no gradle file is generated

Fixes #1593
@julienp julienp changed the title julienp/gradle nexus Default to using gradle-nexus in gen-sdk Jan 30, 2025
@julienp julienp force-pushed the julienp/gradle-nexus branch from 386cdc0 to 6f67b55 Compare January 30, 2025 16:48
@@ -1,15 +1,15 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

package com.pulumi.kubernetes.core_v1;
package com.pulumi.kubernetes.core.v1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the tests ignored any language specific settings. They now no longer do, and this change comes from the config

    "java": {
      "packages": {
        "core/v1": "core.v1",
        "helm.sh/v3": "helm.v3",
        "meta/v1": "meta.v1"
      }
    },

@julienp julienp marked this pull request as ready for review January 30, 2025 17:08
@julienp julienp requested a review from a team as a code owner January 30, 2025 17:08
Copy link
Contributor

@lunaris lunaris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff! And amazing PR description 💜

// legacy behavior requires explicit gradle setting
(legacyBuildFiles && info.BuildFiles == "gradle") ||
// new behavior uses gradle by default, unless explicitly disabled
(!legacyBuildFiles && info.BuildFiles != "none")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I'd make this an if, which although a bit more verbose might be clearer and obviate some of the comment. E.g.:

var useGradle bool
if local {
  // ...
  useGradle = false
} else {
  if legacyBuildFiles {
    // The default for legacy invocations is "none", so we need to see an explicit "gradle" setting
    useGradle = info.BuildFiles == "gradle"
  } else {
    // The default for new invocations is gradle, unless "none" is specified explicitly
    useGradle = info.BuildFiles != "none"
  }
}

info := pkg.Language["java"].(PackageInfo)
pkg.Language["java"] = info.With(testCase.packageInfo)
}
return GeneratePackage(tool, pkg, extraFiles, nil, false /*local*/, false /*legacyBuildFiles*/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if it's possible to find a way to test this set to true, since that's the behaviour we want to preserve, but equally it's probably fine?

@@ -126,7 +130,20 @@ func newGradleTemplateContext(
ctx.Version = pkg.Parameterization.BaseProvider.Version.String()
}

if packageInfo.GradleNexusPublishPluginVersion != "" {
if legacyBuildFiles {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth adding some version of the amazing table in the PR description here; happy either way though.

PackageInfo Behaviour
buildFiles: none no gradle file
buildFiles: gradle-nexus gradle file with nexus plugin, using default version of the plugin, 2.0.0, the default
buildFiles: gradle-nexus, gradleNexusPublishPluginVersion: $VER gradle file with nexus plugin, using version $VER of the plugin
buildFiles: gradle gradle file without nexus plugin
buildFiles: gradle, gradleNexusPublishPluginVersion: $VER gradle file with nexus plugin, using version $VER of the plugin

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 this pull request may close these issues.

Add schema build config
2 participants