Skip to content

Commit

Permalink
feat(pacmak/java): isolate maven repositories (#1709)
Browse files Browse the repository at this point in the history
When preparing a Java package using Maven, `jsii-pacmak` now configures
a dedicated `localRepository` for its own use. This prevents artifacts
cached from previous builds as well as local build artifacts to possibly
interfere with the compilation process.

This has the side-effect to force a re-download of all dependencies on
each build (except those that are generated as part of the same build),
which results in a performance degradation. It should be possible to
make the local repository location user-configurable so this impact can
be mitigated on a case-by-case basis.



---

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
  • Loading branch information
RomainMuller authored Jun 2, 2020
1 parent 81ab944 commit 4904cd8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/@jsii/java-runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.m2
.vscode
*.js
*.d.ts
Expand Down
1 change: 1 addition & 0 deletions packages/@jsii/java-runtime/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mkdir -p conf

# generate pom.xml and JsiiVersion.java with version from package.json
/usr/bin/env node ./pom.xml.t.js > ${project}/pom.xml
/usr/bin/env node ./user.xml.t.js > ${project}/user.xml
/usr/bin/env node JsiiVersion.t.js > ${project}/src/main/java/software/amazon/jsii/JsiiVersion.java

# embed @jsii/runtime as a resource
Expand Down
4 changes: 2 additions & 2 deletions packages/@jsii/java-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"types": "lib/index.d.ts",
"scripts": {
"gen": "/bin/bash ./generate.sh",
"build": "tsc --build && npm run gen && cd project && mvn -B deploy -D altDeploymentRepository=local::default::file://${PWD}/../maven-repo",
"dist-clean": "rm -rf dist maven-repo && cd project && mvn -B clean",
"build": "tsc --build && npm run gen && cd project && mvn -B deploy -D altDeploymentRepository=local::default::file://${PWD}/../maven-repo --settings=user.xml",
"dist-clean": "rm -rf dist maven-repo && cd project && mvn -B clean --settings=user.xml",
"test": "echo 'Tests are run as part of the build target'",
"test:update": "UPDATE_DIFF=1 npm run test",
"package": "package-java && package-private"
Expand Down
1 change: 1 addition & 0 deletions packages/@jsii/java-runtime/project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bin/
!index.js
.idea
pom.xml
user.xml

# generated by JsiiVersion.java.t.js
src/main/java/software/amazon/jsii/JsiiVersion.java
Expand Down
13 changes: 13 additions & 0 deletions packages/@jsii/java-runtime/user.xml.t.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const jsiiJavaRuntime = require('@jsii/java-runtime');
const path = require('path');

process.stdout.write(`<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- Generated by ${__filename} at ${new Date().toISOString()} -->
<localRepository>${path.resolve(__dirname, 'project', '.m2', 'repository')}</localRepository>
</settings>
`);
9 changes: 7 additions & 2 deletions packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,17 @@ export class JavaBuilder implements TargetBuilder {
'#comment': [
`Generated by jsii-pacmak@${VERSION_DESC} on ${new Date().toISOString()}`,
],
// Do *not* attempt to ask the user for stuff...
interactiveMode: false,
// Use a non-default local repository to isolate from cached artifacts...
localRepository: path.resolve(where, '.m2', 'repository'),
// Register locations of locally-sourced dependencies
profiles: {
profile: {
id: profileName,
repositories: {
repository: localRepos.map((repo, index) => ({
id: `local${index}`,
repository: localRepos.map((repo) => ({
id: repo,
url: `file://${repo}`,
})),
},
Expand Down

0 comments on commit 4904cd8

Please sign in to comment.