Skip to content

Commit

Permalink
fix(java): publishing to maven central requires more publishing metad…
Browse files Browse the repository at this point in the history
…ata (#5332)
  • Loading branch information
dsinghvi authored Dec 4, 2024
1 parent a23a661 commit 2f63755
Show file tree
Hide file tree
Showing 207 changed files with 7,546 additions and 76 deletions.
4 changes: 4 additions & 0 deletions fern/pages/changelogs/cli/2024-12-03.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.45.2
**`(fix):`** Example generation now respects read-only schemas when generating request examples.


4 changes: 4 additions & 0 deletions fern/pages/changelogs/java-sdk/2024-12-04.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2.3.0
**`(feat):`** Fix publishing to Maven Central with proper signing configuration and metadata.


Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,30 @@ private void addRootProjectFiles(
.generatorConfig(generatorConfig)
.shouldSignPackage(addSignaturePlugin)
.addAllDependencies(getBuildGradleDependencies())
.addCustomBlocks("tasks.withType(Javadoc) {\n" + " failOnError false\n"
+ " options.addStringOption('Xdoclint:none', '-quiet')\n"
+ "}")
.addCustomBlocks("spotless {\n" + " java {\n" + " palantirJavaFormat()\n" + " }\n" + "}\n")
.addCustomBlocks("java {\n" + " withSourcesJar()\n" + " withJavadocJar()\n" + "}\n");
if (maybeMavenCoordinate.isPresent()) {
buildGradle.addCustomBlocks("group = '" + maybeMavenCoordinate.get().getGroup() + "'");
buildGradle.addCustomBlocks(
"version = '" + maybeMavenCoordinate.get().getVersion() + "'");

buildGradle.addCustomBlocks("jar {\n" + " dependsOn(\":generatePomFileForMavenPublication\")\n"
+ " archiveBaseName = \""
+ maybeMavenCoordinate.get().getArtifact() + "\"\n" + "}");
buildGradle.addCustomBlocks("sourcesJar {\n" + " archiveBaseName = \""
+ maybeMavenCoordinate.get().getArtifact() + "\"\n" + "}");
buildGradle.addCustomBlocks("javadocJar {\n" + " archiveBaseName = \""
+ maybeMavenCoordinate.get().getArtifact() + "\"\n" + "}");
}
if (addSignaturePlugin) {
buildGradle.addPlugins(GradlePlugin.builder().pluginId("signing").build());
buildGradle.addPlugins(GradlePlugin.builder()
.pluginId("cl.franciscosolis.sonatype-central-upload")
.version("1.0.3")
.build());
buildGradle.addCustomBlocks("signing {\n" + " sign(publishing.publications)\n" + "}");
// Generate an empty gradle.properties file
addGeneratedFile(GeneratedGradleProperties.getGeneratedFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public final String getContents() {
writer.addLine("targetCompatibility = 1.8");
writer.addNewLine();

customBlocks().forEach(writer::addLine);
customBlocks().forEach((block) -> {
writer.addLine((block));
writer.addNewLine();
});

// add publishing
if (gradlePublishingConfig().isPresent()) {
Expand All @@ -108,18 +111,47 @@ public final String getContents() {
writer.endControlFlow();
writer.endControlFlow();

writer.beginControlFlow("repositories");
writer.beginControlFlow("maven");
writer.addLine("url \"$System.env." + MAVEN_PUBLISH_REGISTRY_URL_ENV_VAR + "\"");
writer.beginControlFlow("credentials");
writer.addLine("username \"$System.env." + MAVEN_USERNAME_ENV_VAR + "\"");
writer.addLine("password \"$System.env." + MAVEN_PASSWORD_ENV_VAR + "\"");
writer.endControlFlow();
writer.endControlFlow();
writer.endControlFlow();

if (!shouldSignPackage()) {
writer.beginControlFlow("repositories");
writer.beginControlFlow("maven");
writer.addLine("url \"$System.env." + MAVEN_PUBLISH_REGISTRY_URL_ENV_VAR + "\"");
writer.beginControlFlow("credentials");
writer.addLine("username \"$System.env." + MAVEN_USERNAME_ENV_VAR + "\"");
writer.addLine("password \"$System.env." + MAVEN_PASSWORD_ENV_VAR + "\"");
writer.endControlFlow();
writer.endControlFlow();
writer.endControlFlow();
}
writer.endControlFlow();
writer.addNewLine();

if (shouldSignPackage()) {
writer.beginControlFlow("sonatypeCentralUpload");
writer.addLine("username = \"$System.env." + MAVEN_USERNAME_ENV_VAR + "\"");
writer.addLine("password = \"$System.env." + MAVEN_PASSWORD_ENV_VAR + "\"");
writer.addNewLine();
writer.addLine("archives = files(");
writer.addLine(" \"$buildDir/libs/"
+ gradlePublishingConfig().get().artifact() + "-\" + version + \".jar\",");
writer.addLine(" \"$buildDir/libs/"
+ gradlePublishingConfig().get().artifact() + "-\" + version + \"-sources.jar\",");
writer.addLine(" \"$buildDir/libs/"
+ gradlePublishingConfig().get().artifact() + "-\" + version + \"-javadoc.jar\"");
writer.addLine(")");
writer.addNewLine();
writer.addLine("pom = file(\"$buildDir/publications/maven/pom-default.xml\")");
writer.addLine("signingKey = \"$System.env." + MAVEN_SIGNING_KEY + "\"");
writer.addLine("signingKeyPassphrase = \"$System.env." + MAVEN_SIGNING_PASSWORD + "\"");
writer.endControlFlow();
writer.addNewLine();

writer.beginControlFlow("signing");
writer.addLine("def signingKeyId = \"$System.env." + MAVEN_SIGNING_KEY + "\"");
writer.addLine("def signingPassword = \"$System.env." + MAVEN_SIGNING_PASSWORD + "\"");
writer.addLine("useInMemoryPgpKeys(signingKeyId, signingPassword)");
writer.addLine("sign publishing.publications.maven");
writer.endControlFlow();
}
}
return writer.getContents();
}
Expand Down Expand Up @@ -179,6 +211,13 @@ public String visitUnknown(String s) {
writer.addLine("name = '" + license.get() + "'");
writer.endControlFlow();
writer.endControlFlow();
} else {
writer.beginControlFlow("licenses");
writer.beginControlFlow("license");
writer.addLine("name = 'The MIT License (MIT)'");
writer.addLine("url = 'https://mit-license.org/'");
writer.endControlFlow();
writer.endControlFlow();
}

if (pm.isPresent()
Expand Down
8 changes: 8 additions & 0 deletions generators/java/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
- changelogEntry:
- summary: |
Fix publishing to Maven Central with proper signing configuration and metadata.
type: feat
createdAt: '2024-12-04'
irVersion: 46
version: 2.3.0

- changelogEntry:
- summary: |
We now provide endpoint methods for streaming byte array requests in addition to the previous methods accepting
Expand Down
2 changes: 1 addition & 1 deletion packages/seed/build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function main() {
await tsup.build({
entry: ['src/cli.ts'],
format: ['cjs'],
minify: true,
minify: false,
outDir: 'dist',
env: {
CLI_NAME: "seed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DockerTestRunner extends TestRunner {
reviewers: undefined,
audiences: selectAudiences != null ? { type: "select", audiences: selectAudiences } : ALL_AUDIENCES,
generators: [
getGeneratorInvocation({
await getGeneratorInvocation({
absolutePathToOutput: outputDir,
docker: this.getParsedDockerName(),
language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class LocalTestRunner extends TestRunner {
const localOutputDirectory = await tmp.dir();
const absolutePathToLocalOutputDirectory = AbsoluteFilePath.of(localOutputDirectory.path);

const generatorInvocation = getGeneratorInvocation({
const generatorInvocation = await getGeneratorInvocation({
absolutePathToOutput: absolutePathToLocalOutputDirectory,
docker: this.getParsedDockerName(),
language,
Expand Down
21 changes: 14 additions & 7 deletions packages/seed/src/utils/getGeneratorInvocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { generatorsYml } from "@fern-api/configuration";
import { assertNever } from "@fern-api/core-utils";
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { FernFiddle } from "@fern-fern/fiddle-sdk";
import * as FernFiddleSerialization from "@fern-fern/fiddle-sdk/serialization";
import { GithubPublishInfo, PublishOutputModeV2 } from "@fern-fern/fiddle-sdk/api";
import { OutputMode } from "../config/api";
import { ParsedDockerName } from "../utils/parseDockerOrThrow";

export function getGeneratorInvocation({
export async function getGeneratorInvocation({
absolutePathToOutput,
docker,
language,
Expand All @@ -28,26 +29,29 @@ export function getGeneratorInvocation({
irVersion: string;
publishMetadata: unknown;
readme: generatorsYml.ReadmeSchema | undefined;
}): generatorsYml.GeneratorInvocation {
}): Promise<generatorsYml.GeneratorInvocation> {
return {
name: docker.name,
version: docker.version,
config: customConfig,
outputMode: getOutputMode({ outputMode, language, fixtureName, publishConfig }),
outputMode: await getOutputMode({ outputMode, language, fixtureName, publishConfig }),
absolutePathToLocalOutput: absolutePathToOutput,
absolutePathToLocalSnippets: undefined,
language,
keywords: undefined,
smartCasing: false,
disableExamples: false,
irVersionOverride: irVersion,
publishMetadata: publishMetadata != null ? (publishMetadata as FernFiddle.PublishingMetadata) : undefined,
publishMetadata:
publishMetadata != null
? await FernFiddleSerialization.PublishingMetadata.parseOrThrow(publishMetadata)
: undefined,
readme,
settings: undefined
};
}

function getOutputMode({
async function getOutputMode({
outputMode,
language,
fixtureName,
Expand All @@ -57,10 +61,13 @@ function getOutputMode({
language: generatorsYml.GenerationLanguage | undefined;
fixtureName: string;
publishConfig: unknown;
}): FernFiddle.OutputMode {
}): Promise<FernFiddle.OutputMode> {
switch (outputMode) {
case "github":
const githubPublishInfo = publishConfig != null ? (publishConfig as GithubPublishInfo) : undefined;
const githubPublishInfo =
publishConfig != null
? await FernFiddleSerialization.GithubPublishInfo.parseOrThrow(publishConfig)
: undefined;
return FernFiddle.OutputMode.github({
repo: "fern",
owner: fixtureName,
Expand Down
31 changes: 31 additions & 0 deletions seed/java-model/alias/build.gradle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions seed/java-model/any-auth/build.gradle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2f63755

Please sign in to comment.