Skip to content

Commit 2198295

Browse files
authored
fix(pacmak): dependency ranges make Maven download too many files (#5006)
Given a dependency version range, Maven will download metadata for all possible versions before every (uncached) build. This takes a long time, before finally resolving to the latest version anyway. Instead, we use the Maven 'versions' plugin to resolve our wide ranges to point versions. We want the "latest matching" version anyway, and if we don't the resolution now (which downloads the .poms of all possible versions) it will happen during every single build. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent e208a72 commit 2198295

File tree

1 file changed

+32
-0
lines changed
  • packages/jsii-pacmak/lib/targets

1 file changed

+32
-0
lines changed

packages/jsii-pacmak/lib/targets/java.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ export class JavaBuilder implements TargetBuilder {
9191
);
9292
scratchDirs.push(tempSourceDir);
9393

94+
await resolveMavenVersions(tempSourceDir.directory);
95+
9496
// Need any old module object to make a target to be able to invoke build, though none of its settings
9597
// will be used.
9698
const target = this.makeTarget(this.modules[0], this.options);
9799
const tempOutputDir = await Scratch.make(async (dir) => {
98100
logging.debug(`Building Java code to ${dir}`);
101+
99102
await target.build(tempSourceDir.directory, dir);
100103
});
101104
scratchDirs.push(tempOutputDir);
@@ -4009,3 +4012,32 @@ function removeIntersections(x: spec.TypeReference): spec.TypeReference {
40094012
}
40104013
return x;
40114014
}
4015+
4016+
/**
4017+
* Run the maven 'versions:resolve-ranges' plugin
4018+
*
4019+
* Initially, we generate version ranges into the pom file based on the NPM
4020+
* version ranges.
4021+
*
4022+
* At build time, given a dependency version range, Maven will download metadata
4023+
* for all possible versions before every (uncached) build. This takes a long
4024+
* time, before finally resolving to the latest version anyway.
4025+
*
4026+
* Instead, we use the Maven 'versions' plugin to resolve our wide ranges to
4027+
* point versions. We want the "latest matching" version anyway, and if we don't
4028+
* the resolution now (which downloads the .poms of all possible versions) it
4029+
* will happen during every single build.
4030+
*/
4031+
async function resolveMavenVersions(directory: string) {
4032+
const versionsPluginVersion = '2.20.1';
4033+
await subprocess(
4034+
'mvn',
4035+
[
4036+
`org.codehaus.mojo:versions-maven-plugin:${versionsPluginVersion}:resolve-ranges`,
4037+
],
4038+
{
4039+
cwd: directory,
4040+
retry: { maxAttempts: 1 },
4041+
},
4042+
);
4043+
}

0 commit comments

Comments
 (0)