@@ -26,7 +26,14 @@ import {
2626 findLocalBuildDirs ,
2727 TargetOptions ,
2828} from '../target' ;
29- import { subprocess , Scratch , slugify , setExtend , zip } from '../util' ;
29+ import {
30+ subprocess ,
31+ Scratch ,
32+ slugify ,
33+ setExtend ,
34+ zip ,
35+ ShellOptions ,
36+ } from '../util' ;
3037import { VERSION , VERSION_DESC } from '../version' ;
3138import { stabilityPrefixFor , renderSummary } from './_utils' ;
3239import { toMavenVersionRange , toReleaseVersion } from './version-utils' ;
@@ -100,11 +107,12 @@ export class JavaBuilder implements TargetBuilder {
100107 ) ;
101108 scratchDirs . push ( tempSourceDir ) ;
102109
103- await resolveMavenVersions ( tempSourceDir . directory ) ;
104-
105110 // Need any old module object to make a target to be able to invoke build, though none of its settings
106111 // will be used.
107112 const target = this . makeTarget ( this . modules [ 0 ] , this . options ) ;
113+
114+ await target . resolveMavenVersions ( tempSourceDir . directory ) ;
115+
108116 const tempOutputDir = await Scratch . make ( async ( dir ) => {
109117 logging . debug ( `Building Java code to ${ dir } ` ) ;
110118
@@ -348,7 +356,7 @@ export class JavaBuilder implements TargetBuilder {
348356 return filePath ;
349357 }
350358
351- private makeTarget ( module : JsiiModule , options : BuildOptions ) : Target {
359+ private makeTarget ( module : JsiiModule , options : BuildOptions ) : Java {
352360 return new Java ( {
353361 arguments : options . arguments ,
354362 assembly : module . assembly ,
@@ -449,13 +457,57 @@ export default class Java extends Target {
449457
450458 public async build ( sourceDir : string , outDir : string ) : Promise < void > {
451459 const url = `file://${ outDir } ` ;
452- const mvnArguments = new Array < string > ( ) ;
460+
461+ await this . invokeMaven (
462+ sourceDir ,
463+ [ 'deploy' , `-D=altDeploymentRepository=local::default::${ url } ` ] ,
464+ {
465+ retry : { maxAttempts : 5 } ,
466+ } ,
467+ ) ;
468+ }
469+
470+ /**
471+ * Run the maven 'versions:resolve-ranges' plugin
472+ *
473+ * Initially, we generate version ranges into the pom file based on the NPM
474+ * version ranges.
475+ *
476+ * At build time, given a dependency version range, Maven will download metadata
477+ * for all possible versions before every (uncached) build. This takes a long
478+ * time, before finally resolving to the latest version anyway.
479+ *
480+ * Instead, we use the Maven 'versions' plugin to resolve our wide ranges to
481+ * point versions. We want the "latest matching" version anyway, and if we don't
482+ * the resolution now (which downloads the .poms of all possible versions) it
483+ * will happen during every single build.
484+ */
485+ public async resolveMavenVersions ( directory : string ) {
486+ const versionsPluginVersion = '2.20.1' ;
487+ await this . invokeMaven (
488+ directory ,
489+ [
490+ `org.codehaus.mojo:versions-maven-plugin:${ versionsPluginVersion } :resolve-ranges` ,
491+ ] ,
492+ {
493+ retry : { maxAttempts : 1 } ,
494+ } ,
495+ ) ;
496+ }
497+
498+ private async invokeMaven (
499+ directory : string ,
500+ args : string [ ] ,
501+ options ?: Omit < ShellOptions , 'cwd' > ,
502+ ) {
503+ // Pass through jsii-pacmak --mvn-xyz=... arguments as --xyz=...
504+ const passThruArgs = new Array < string > ( ) ;
453505 for ( const arg of Object . keys ( this . arguments ) ) {
454506 if ( ! arg . startsWith ( 'mvn-' ) ) {
455507 continue ;
456508 }
457- mvnArguments . push ( `--${ arg . slice ( 4 ) } ` ) ;
458- mvnArguments . push ( this . arguments [ arg ] . toString ( ) ) ;
509+ passThruArgs . push ( `--${ arg . slice ( 4 ) } ` ) ;
510+ passThruArgs . push ( this . arguments [ arg ] . toString ( ) ) ;
459511 }
460512
461513 await subprocess (
@@ -464,21 +516,21 @@ export default class Java extends Target {
464516 // If we don't run in verbose mode, turn on quiet mode
465517 ...( this . arguments . verbose ? [ ] : [ '--quiet' ] ) ,
466518 '--batch-mode' ,
467- ...mvnArguments ,
468- 'deploy' ,
469- `-D=altDeploymentRepository=local::default::${ url } ` ,
519+ ...args ,
520+ ...passThruArgs ,
470521 '--settings=user.xml' ,
471522 ] ,
472523 {
473- cwd : sourceDir ,
524+ cwd : directory ,
474525 env : {
475526 // Twiddle the JVM settings a little for Maven. Delaying JIT compilation
476527 // brings down Maven execution time by about 1/3rd (15->10s, 30->20s)
477528 MAVEN_OPTS : `${
478529 process . env . MAVEN_OPTS ?? ''
479530 } -XX:+TieredCompilation -XX:TieredStopAtLevel=1`,
531+ ...options ?. env ,
480532 } ,
481- retry : { maxAttempts : 5 } ,
533+ ... options ,
482534 } ,
483535 ) ;
484536 }
@@ -4056,36 +4108,6 @@ function removeIntersections(x: spec.TypeReference): spec.TypeReference {
40564108 return x ;
40574109}
40584110
4059- /**
4060- * Run the maven 'versions:resolve-ranges' plugin
4061- *
4062- * Initially, we generate version ranges into the pom file based on the NPM
4063- * version ranges.
4064- *
4065- * At build time, given a dependency version range, Maven will download metadata
4066- * for all possible versions before every (uncached) build. This takes a long
4067- * time, before finally resolving to the latest version anyway.
4068- *
4069- * Instead, we use the Maven 'versions' plugin to resolve our wide ranges to
4070- * point versions. We want the "latest matching" version anyway, and if we don't
4071- * the resolution now (which downloads the .poms of all possible versions) it
4072- * will happen during every single build.
4073- */
4074- async function resolveMavenVersions ( directory : string ) {
4075- const versionsPluginVersion = '2.20.1' ;
4076- await subprocess (
4077- 'mvn' ,
4078- [
4079- `org.codehaus.mojo:versions-maven-plugin:${ versionsPluginVersion } :resolve-ranges` ,
4080- '--settings=user.xml' ,
4081- ] ,
4082- {
4083- cwd : directory ,
4084- retry : { maxAttempts : 1 } ,
4085- } ,
4086- ) ;
4087- }
4088-
40894111/**
40904112 * Whether the given property or method needs to be implemented on a $Proxy class
40914113 *
0 commit comments