Skip to content

Commit 09420b6

Browse files
authored
fix: add default licenses property to pom.xml and remove support for licenseOptions in Java (#733)
1 parent 1f530c1 commit 09420b6

File tree

5 files changed

+355
-13
lines changed

5 files changed

+355
-13
lines changed

packages/infrastructure/test/projects/java/__snapshots__/infrastructure-java-project.test.ts.snap

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/monorepo/src/components/nx-configurator.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -500,22 +500,39 @@ export class NxConfigurator extends Component implements INxProjectCore {
500500
* Add licenses to any subprojects which don't already have a license.
501501
*/
502502
private _addLicenses() {
503-
this.project.subprojects
503+
[this.project, ...this.project.subprojects]
504504
.filter(
505505
(p) => p.components.find((c) => c instanceof License) === undefined
506506
)
507507
.forEach((p) => {
508-
if (!this.licenseOptions || this.licenseOptions.spdx) {
508+
if (!this.licenseOptions) {
509509
new License(p, {
510-
spdx: this.licenseOptions?.spdx ?? DEFAULT_LICENSE,
511-
copyrightOwner: this.licenseOptions?.copyrightOwner,
510+
spdx: DEFAULT_LICENSE,
512511
});
512+
if (ProjectUtils.isNamedInstanceOf(p, JavaProject)) {
513+
// Force all Java projects to use Apache 2.0
514+
p.tryFindObjectFile("pom.xml")?.addOverride("project.licenses", [
515+
{
516+
license: {
517+
name: "Apache License 2.0",
518+
url: "https://www.apache.org/licenses/LICENSE-2.0",
519+
distribution: "repo",
520+
comments: "An OSI-approved license",
521+
},
522+
},
523+
]);
524+
}
513525
} else if (!!this.licenseOptions?.licenseText) {
514526
new TextFile(p, "LICENSE", {
515527
marker: false,
516528
committed: true,
517529
lines: this.licenseOptions.licenseText.split("\n"),
518530
});
531+
} else if (this.licenseOptions.spdx) {
532+
new License(p, {
533+
spdx: this.licenseOptions.spdx,
534+
copyrightOwner: this.licenseOptions?.copyrightOwner,
535+
});
519536
} else {
520537
throw new Error("Either spdx or licenseText must be specified.");
521538
}

packages/monorepo/src/projects/java/monorepo-java.ts

-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { JavaProjectOptions } from "./java-project-options";
99
import {
1010
NxConfigurator,
1111
INxProjectCore,
12-
LicenseOptions,
1312
} from "../../components/nx-configurator";
1413
import { NxWorkspace } from "../../components/nx-workspace";
1514
import {
@@ -26,13 +25,6 @@ const MVN_PLUGIN_PATH = "./.nx/plugins/nx_plugin.js";
2625
*/
2726
export interface MonorepoJavaOptions extends JavaProjectOptions {
2827
readonly defaultReleaseBranch?: string;
29-
30-
/**
31-
* Default license to apply to all PDK managed packages.
32-
*
33-
* @default Apache-2.0
34-
*/
35-
readonly licenseOptions?: LicenseOptions;
3628
}
3729

3830
/**
@@ -80,7 +72,6 @@ export class MonorepoJavaProject extends JavaProject implements INxProjectCore {
8072

8173
this.nxConfigurator = new NxConfigurator(this, {
8274
defaultReleaseBranch: options.defaultReleaseBranch ?? "main",
83-
licenseOptions: options.licenseOptions,
8475
});
8576

8677
// Setup maven nx plugin

0 commit comments

Comments
 (0)