diff --git a/lib/manager/maven/extract.js b/lib/manager/maven/extract.js index 583a9819ea2a0e9086668e2027c554607ce2cdd8..36ad0dcc097d461e22e6d13de16305162c043d64 100644 --- a/lib/manager/maven/extract.js +++ b/lib/manager/maven/extract.js @@ -1,6 +1,8 @@ const { XmlDocument } = require('xmldoc'); const { isVersion } = require('../../versioning/maven'); +const DEFAULT_MAVEN_REPO = 'https://repo.maven.apache.org/maven2'; + function parsePom(raw) { let project; try { @@ -40,7 +42,7 @@ function depFromNode(node) { const offset = '<version>'.length - 1; result.fileReplacePosition = versionNode.startTagPosition + offset; result.datasource = 'maven'; - result.registryUrls = ['https://repo.maven.apache.org/maven2']; + result.registryUrls = [DEFAULT_MAVEN_REPO]; } return result; } @@ -80,6 +82,22 @@ function extractDependencies(raw) { result.deps = deepExtract(project); + const repositories = project.childNamed('repositories'); + if (repositories && repositories.children) { + const repoUrls = []; + for (const repo of repositories.childrenNamed('repository')) { + const repoUrl = repo.valueWithPath('url'); + if (repoUrl) { + repoUrls.push(repoUrl); + } + } + result.deps.forEach(dep => { + if (dep.registryUrls) { + repoUrls.forEach(url => dep.registryUrls.push(url)); + } + }); + } + return result; } diff --git a/test/_fixtures/maven/simple.pom.xml b/test/_fixtures/maven/simple.pom.xml index 0151002b32a27b73f540ba902ff173b7c0278f45..e11ebf54d43780b1ac4124b60a3f0d5e29e45849 100644 --- a/test/_fixtures/maven/simple.pom.xml +++ b/test/_fixtures/maven/simple.pom.xml @@ -124,4 +124,16 @@ </plugin> </plugins> </reporting> + + <repositories> + <repository> + <id>atlassian</id> + <name>Atlassian Repository</name> + <url>https://maven.atlassian.com/content/repositories/atlassian-public/</url> + </repository> + <repository> + <id>nonsense</id> + <name>The item without url</name> + </repository> + </repositories> </project> diff --git a/test/manager/maven/__snapshots__/extract.spec.js.snap b/test/manager/maven/__snapshots__/extract.spec.js.snap index c896b7798167fd305c68b0c1f9e7524800faf86f..6a563704d9514e78f25ab3b518cb1516204bf07e 100644 --- a/test/manager/maven/__snapshots__/extract.spec.js.snap +++ b/test/manager/maven/__snapshots__/extract.spec.js.snap @@ -11,6 +11,7 @@ Object { "fileReplacePosition": 186, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -20,6 +21,7 @@ Object { "fileReplacePosition": 757, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -29,6 +31,7 @@ Object { "fileReplacePosition": 905, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -38,6 +41,7 @@ Object { "fileReplacePosition": 1337, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -62,6 +66,7 @@ Object { "fileReplacePosition": 2529, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -81,6 +86,7 @@ Object { "fileReplacePosition": 3218, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, ],