diff --git a/plugins/maven/__tests__/maven.test.ts b/plugins/maven/__tests__/maven.test.ts
index a338e9e76..9cf46bf04 100644
--- a/plugins/maven/__tests__/maven.test.ts
+++ b/plugins/maven/__tests__/maven.test.ts
@@ -270,9 +270,13 @@ describe("maven", () => {
await hooks.version.promise({ bump: Auto.SEMVER.patch });
const call = exec.mock.calls[0][1];
- expect(call).toContain("tag");
- expect(call).toContain("v1.0.0");
- expect(call).toContain('"Update version to v1.0.0"');
+ expect(call).toContain("help:effective-pom");
+ expect(call).toContain("-Doutput=target/output.xml");
+
+ const secondCall = exec.mock.calls[1][1];
+ expect(secondCall).toContain("tag");
+ expect(secondCall).toContain("v1.0.0");
+ expect(secondCall).toContain('"Update version to v1.0.0"');
});
test("should version release", async () => {
@@ -290,9 +294,13 @@ describe("maven", () => {
await hooks.version.promise({ bump: Auto.SEMVER.patch });
const call = exec.mock.calls[0][1];
- expect(call).toContain("tag");
- expect(call).toContain("v1.0.1");
- expect(call).toContain('"Update version to v1.0.1"');
+ expect(call).toContain("help:effective-pom");
+ expect(call).toContain("-Doutput=target/output.xml");
+
+ const secondCall = exec.mock.calls[1][1];
+ expect(secondCall).toContain("tag");
+ expect(secondCall).toContain("v1.0.1");
+ expect(secondCall).toContain('"Update version to v1.0.1"');
});
test("should replace the previousVersion with the newVersion", async () => {
@@ -359,9 +367,37 @@ describe("maven", () => {
);
const call = exec.mock.calls[0][1];
- expect(call).toContain("versions:set");
- expect(call).toContain("-DgenerateBackupPoms=false");
- expect(call).toContain("-DnewVersion=1.0.0");
+ expect(call).toContain("help:effective-pom");
+ expect(call).toContain("-Doutput=target/output.xml");
+
+ const secondCall = exec.mock.calls[1][1];
+ expect(secondCall).toContain("versions:set");
+ expect(secondCall).toContain("-DgenerateBackupPoms=false");
+ expect(secondCall).toContain("-DnewVersion=1.0.0");
+ });
+
+ test("should create effective POM file successfully", async () => {
+ mockReadFile(`
+ 1.0.0-SNAPSHOT
+
+
+
+ org.codehaus.mojo
+ versions-maven-plugin
+ 2.7
+
+
+
+ `);
+
+ await hooks.beforeRun.promise({} as any);
+
+ const call = exec.mock.calls[0][1];
+ expect(call).toContain("help:effective-pom");
+ expect(call).toContain("-Doutput=target/output.xml");
});
test("should replace the parent previousVersion with the newVersion", async () => {
@@ -468,7 +504,11 @@ describe("maven", () => {
await hooks.publish.promise({ bump: Auto.SEMVER.patch });
- expect(exec.mock.calls[0][1]).toContain("deploy");
+ const call = exec.mock.calls[0][1];
+ expect(call).toContain("help:effective-pom");
+ expect(call).toContain("-Doutput=target/output.xml");
+
+ expect(exec.mock.calls[1][1]).toContain("deploy");
});
});
});
diff --git a/plugins/maven/src/index.ts b/plugins/maven/src/index.ts
index 2fc129cc8..bcb69fa0c 100644
--- a/plugins/maven/src/index.ts
+++ b/plugins/maven/src/index.ts
@@ -111,8 +111,9 @@ export default class MavenPlugin implements IPlugin {
}
/** Detect whether the parent pom.xml has the versions-maven-plugin **/
- private static async detectVersionMavenPlugin(): Promise {
- const pom = await getPom();
+ private static async detectVersionMavenPlugin(options: IMavenPluginOptions, auto: Auto): Promise {
+ await maven.createEffectivePom(options, auto);
+ const pom = await getPom("target/output.xml");
const pomDom = new jsdom.JSDOM(pom.pomXml, { contentType: "text/xml" })
.window.document;
const versionsMavenPluginNode = pomDom.evaluate(
@@ -182,7 +183,7 @@ export default class MavenPlugin implements IPlugin {
this.snapshotRelease = true;
}
- this.versionsMavenPlugin = await MavenPlugin.detectVersionMavenPlugin();
+ this.versionsMavenPlugin = await MavenPlugin.detectVersionMavenPlugin(this.options, auto);
});
auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => {
diff --git a/plugins/maven/src/maven.ts b/plugins/maven/src/maven.ts
index bd04c9c7d..d635ae449 100644
--- a/plugins/maven/src/maven.ts
+++ b/plugins/maven/src/maven.ts
@@ -49,3 +49,23 @@ export async function updatePoms(
await execPromise("git", ["commit", "-am", message, "--no-verify"]);
}
+
+/** Create effective pom file with maven */
+export async function createEffectivePom(
+ options: IMavenPluginOptions,
+ auto: Auto
+) {
+ auto.logger.verbose.info(
+ `Creating effective-pom file in target directory`
+ );
+
+ try {
+ await executeMaven(options, [
+ "help:effective-pom",
+ "-Doutput=target/output.xml"
+ ]);
+ } catch (error) {
+ auto.logger.verbose.error(`Failed to create effective pom: ${error.message}`);
+ throw new Error(`Failed to create effective pom in target directory`);
+ }
+}