mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-12-02 01:40:33 +00:00
fix(java): resolve repositories from pom.xml, parent POMs and imported BOMs as Maven does (#11437)
This commit is contained in:
1 parent
e7c7720564
commit
3fd6cca8d3
28 files changed
+1767
-93
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
"github.com/aquasecurity/trivy/pkg/set"
|
||||
)
|
||||
|
||||
func Test_mirror_matches(t *testing.T) {
|
||||
@@ -794,9 +795,10 @@ func Test_fetchPOMFromRemoteRepositories_rejectedCredentials(t *testing.T) {
|
||||
paths := []string{"com", "example", "example-api", "1.0.0", "example-api-1.0.0.pom"}
|
||||
for range tt.parsers {
|
||||
p := &Parser{
|
||||
logger: logger,
|
||||
mirrors: resolveMirrors(settingsMirrors, servers, nil),
|
||||
httpClient: http.DefaultClient,
|
||||
logger: logger,
|
||||
mirrors: resolveMirrors(settingsMirrors, servers, nil),
|
||||
httpClient: http.DefaultClient,
|
||||
notFoundPOMs: set.New[string](),
|
||||
}
|
||||
got, err := p.fetchPOMFromRemoteRepositories(t.Context(), paths, tt.snapshot, repos)
|
||||
if tt.wantErr != "" {
|
||||
@@ -845,14 +847,16 @@ func Test_fetchPOMFromRemoteRepositories_mirror(t *testing.T) {
|
||||
// can only be observed end-to-end through HTTP: that mirrorFor is applied to the
|
||||
// fetch loop, that mirror credentials reach the remote request as Basic Auth, that
|
||||
// a settings.xml -> trivy.yaml chain routes the fetch through to the final mirror,
|
||||
// that the fetch falls back to the next trivy.yaml mirror on 404 or 429, and that a
|
||||
// 429 is returned only when every mirror is rate-limited.
|
||||
// that the fetch falls back to the next trivy.yaml mirror on 404 or 429, that a
|
||||
// 429 is returned only when every mirror is rate-limited, and that a POM not found
|
||||
// or denied with a 403 in a mirror is not requested from it again, while a 503 is retried.
|
||||
tests := []struct {
|
||||
name string
|
||||
mirrorPatterns []string
|
||||
mirrorWithCreds bool
|
||||
wantBasicAuth string
|
||||
configMirrors map[string][]string // trivy.yaml mirrors, by server role: source-role -> []mirror-role
|
||||
refetch bool // fetch the same POM again after the first fetch
|
||||
wantHits map[string]int // expected request count per server role
|
||||
wantErr string // non-empty: fetch must fail with an error containing this
|
||||
wantWarn string // non-empty: the logged output must contain this text
|
||||
@@ -880,6 +884,32 @@ func Test_fetchPOMFromRemoteRepositories_mirror(t *testing.T) {
|
||||
configMirrors: map[string][]string{"mirror": {"dead", "chain"}},
|
||||
wantHits: map[string]int{"dead": 1, "chain": 1},
|
||||
},
|
||||
{
|
||||
// The POM is fetched twice; the mirror that 404'd the first time is not requested again.
|
||||
name: "trivy.yaml fallback: not found POM is not requested again",
|
||||
mirrorPatterns: []string{"*"},
|
||||
configMirrors: map[string][]string{"mirror": {"dead", "chain"}},
|
||||
refetch: true,
|
||||
wantHits: map[string]int{"dead": 1, "chain": 2},
|
||||
},
|
||||
{
|
||||
// The POM is fetched twice; the mirror that returned 503 is requested again,
|
||||
// since it may have recovered.
|
||||
name: "trivy.yaml fallback: POM failed with 503 is requested again",
|
||||
mirrorPatterns: []string{"*"},
|
||||
configMirrors: map[string][]string{"mirror": {"unavailable", "chain"}},
|
||||
refetch: true,
|
||||
wantHits: map[string]int{"unavailable": 2, "chain": 2},
|
||||
},
|
||||
{
|
||||
// The POM is fetched twice; a 403 is not expected to change, so the mirror that
|
||||
// returned it is not requested again.
|
||||
name: "trivy.yaml fallback: POM denied with 403 is not requested again",
|
||||
mirrorPatterns: []string{"*"},
|
||||
configMirrors: map[string][]string{"mirror": {"forbidden", "chain"}},
|
||||
refetch: true,
|
||||
wantHits: map[string]int{"forbidden": 1, "chain": 2},
|
||||
},
|
||||
{
|
||||
// A POM that fails to parse is not retried against another repository: the
|
||||
// repository that served it is treated as authoritative, same as Maven.
|
||||
@@ -951,13 +981,15 @@ func Test_fetchPOMFromRemoteRepositories_mirror(t *testing.T) {
|
||||
// repo1: original repository; mirror: settings.xml target; chain/dead:
|
||||
// trivy.yaml targets (dead always 404s).
|
||||
servers := map[string]*httptest.Server{
|
||||
"repo1": newServer("repo1", http.StatusOK, ""),
|
||||
"mirror": newServer("mirror", http.StatusOK, ""),
|
||||
"chain": newServer("chain", http.StatusOK, ""),
|
||||
"dead": newServer("dead", http.StatusNotFound, ""),
|
||||
"limited": newServer("limited", http.StatusTooManyRequests, ""),
|
||||
"broken": newServer("broken", http.StatusOK, "not a pom"),
|
||||
"limit2": newServer("limit2", http.StatusTooManyRequests, ""),
|
||||
"repo1": newServer("repo1", http.StatusOK, ""),
|
||||
"mirror": newServer("mirror", http.StatusOK, ""),
|
||||
"chain": newServer("chain", http.StatusOK, ""),
|
||||
"dead": newServer("dead", http.StatusNotFound, ""),
|
||||
"limited": newServer("limited", http.StatusTooManyRequests, ""),
|
||||
"broken": newServer("broken", http.StatusOK, "not a pom"),
|
||||
"limit2": newServer("limit2", http.StatusTooManyRequests, ""),
|
||||
"unavailable": newServer("unavailable", http.StatusServiceUnavailable, ""),
|
||||
"forbidden": newServer("forbidden", http.StatusForbidden, ""),
|
||||
}
|
||||
|
||||
// trivy.yaml mirrors: resolve role names to server URLs.
|
||||
@@ -986,18 +1018,25 @@ func Test_fetchPOMFromRemoteRepositories_mirror(t *testing.T) {
|
||||
|
||||
var logBuf bytes.Buffer
|
||||
p := &Parser{
|
||||
logger: log.New(log.NewHandler(&logBuf, nil)).With(log.Prefix("pom")),
|
||||
mirrors: resolved,
|
||||
httpClient: http.DefaultClient,
|
||||
logger: log.New(log.NewHandler(&logBuf, nil)).With(log.Prefix("pom")),
|
||||
mirrors: resolved,
|
||||
httpClient: http.DefaultClient,
|
||||
notFoundPOMs: set.New[string](),
|
||||
}
|
||||
|
||||
paths := []string{"com", "example", "example-api", "1.0.0", "example-api-1.0.0.pom"}
|
||||
got, err := p.fetchPOMFromRemoteRepositories(t.Context(), paths, false, []repository{pomRepo})
|
||||
if tt.wantErr != "" {
|
||||
require.Regexp(t, tt.wantErr, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, got)
|
||||
fetch := func() {
|
||||
got, err := p.fetchPOMFromRemoteRepositories(t.Context(), paths, false, []repository{pomRepo})
|
||||
if tt.wantErr != "" {
|
||||
require.Regexp(t, tt.wantErr, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, got)
|
||||
}
|
||||
}
|
||||
fetch()
|
||||
if tt.refetch {
|
||||
fetch()
|
||||
}
|
||||
|
||||
for role := range servers {
|
||||
@@ -1068,8 +1107,9 @@ func Test_fetchPOMFromRemoteRepositories_invalidMetadata(t *testing.T) {
|
||||
|
||||
var logBuf bytes.Buffer
|
||||
p := &Parser{
|
||||
logger: log.New(log.NewHandler(&logBuf, nil)).With(log.Prefix("pom")),
|
||||
httpClient: http.DefaultClient,
|
||||
logger: log.New(log.NewHandler(&logBuf, nil)).With(log.Prefix("pom")),
|
||||
httpClient: http.DefaultClient,
|
||||
notFoundPOMs: set.New[string](),
|
||||
}
|
||||
|
||||
paths := []string{"com", "example", "example-api", "1.0.0-SNAPSHOT", "example-api-1.0.0-SNAPSHOT.pom"}
|
||||
@@ -1131,9 +1171,10 @@ func Test_fetchPOMFromRemoteRepositories_mirrorPolicy(t *testing.T) {
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
p := &Parser{
|
||||
logger: log.WithPrefix("pom"),
|
||||
mirrors: resolveMirrors([]Mirror{{ID: "m1", URL: srv.URL, MirrorOf: "*"}}, nil, nil),
|
||||
httpClient: http.DefaultClient,
|
||||
logger: log.WithPrefix("pom"),
|
||||
mirrors: resolveMirrors([]Mirror{{ID: "m1", URL: srv.URL, MirrorOf: "*"}}, nil, nil),
|
||||
httpClient: http.DefaultClient,
|
||||
notFoundPOMs: set.New[string](),
|
||||
}
|
||||
|
||||
paths := []string{"com", "example", "example-api", tt.version, "example-api-" + tt.version + ".pom"}
|
||||
|
||||
@@ -96,6 +96,8 @@ type Parser struct {
|
||||
logger *log.Logger
|
||||
rootPath string
|
||||
cache pomCache
|
||||
importCache pomCache // POMs imported into dependencyManagement are resolved without dependencies, so they are cached separately
|
||||
notFoundPOMs set.Set[string] // POMs for which remote repositories returned a 4xx response other than 429, keyed by repository URL and POM path
|
||||
localRepository string
|
||||
remoteRepos repositories
|
||||
offline bool
|
||||
@@ -158,6 +160,8 @@ func NewParser(filePath string, opts ...option) *Parser {
|
||||
logger: log.WithPrefix("pom"),
|
||||
rootPath: filepath.Clean(filePath),
|
||||
cache: newPOMCache(),
|
||||
importCache: newPOMCache(),
|
||||
notFoundPOMs: set.New[string](),
|
||||
localRepository: localRepository,
|
||||
remoteRepos: remoteRepos,
|
||||
offline: o.offline,
|
||||
@@ -303,14 +307,14 @@ func (p *Parser) parseRoot(ctx context.Context, root artifact, uniqModules set.S
|
||||
}
|
||||
}
|
||||
|
||||
result, err := p.resolve(ctx, art, rootDepManagement)
|
||||
result, err := p.resolve(ctx, art, rootDepManagement, false)
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("resolve error (%s): %w", art, err)
|
||||
}
|
||||
|
||||
if art.Relationship == ftypes.RelationshipRoot || art.Relationship == ftypes.RelationshipWorkspace {
|
||||
// Managed dependencies in the root POM affect transitive dependencies
|
||||
rootDepManagement, err = p.resolveDepManagement(ctx, result.properties, result.dependencyManagement)
|
||||
rootDepManagement, err = p.resolveDepManagement(ctx, result.properties, result.dependencyManagement, result.artifact.Repositories, set.New[string]())
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("unable to resolve dep management: %w", err)
|
||||
}
|
||||
@@ -324,7 +328,7 @@ func (p *Parser) parseRoot(ctx context.Context, root artifact, uniqModules set.S
|
||||
|
||||
// Parse, cache, and enqueue modules.
|
||||
for _, relativePath := range result.modules {
|
||||
moduleArtifact, err := p.parseModule(ctx, result.filePath, relativePath, root.Repositories)
|
||||
moduleArtifact, err := p.parseModule(ctx, result.filePath, relativePath)
|
||||
if err != nil {
|
||||
p.logger.Debug("Unable to parse the module",
|
||||
log.FilePath(result.filePath), log.Err(err))
|
||||
@@ -403,16 +407,17 @@ func depVersion(depName string, uniqArtifacts map[string]artifact) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *Parser) parseModule(ctx context.Context, currentPath, relativePath string, repos []repository) (artifact, error) {
|
||||
func (p *Parser) parseModule(ctx context.Context, currentPath, relativePath string) (artifact, error) {
|
||||
// modulePath: "root/" + "module/" => "root/module"
|
||||
module, err := p.openRelativePom(currentPath, relativePath)
|
||||
if err != nil {
|
||||
return artifact{}, xerrors.Errorf("unable to open the relative path: %w", err)
|
||||
}
|
||||
|
||||
// As in Maven, repositories of an aggregator POM are not used for its modules,
|
||||
// unless the module inherits them from the aggregator POM as its parent.
|
||||
result, err := p.analyze(ctx, module, analysisOptions{
|
||||
rootFilePath: module.filePath,
|
||||
repositories: repos,
|
||||
})
|
||||
if err != nil {
|
||||
return artifact{}, xerrors.Errorf("analyze error: %w", err)
|
||||
@@ -428,9 +433,14 @@ func (p *Parser) parseModule(ctx context.Context, currentPath, relativePath stri
|
||||
return moduleArtifact, nil
|
||||
}
|
||||
|
||||
func (p *Parser) resolve(ctx context.Context, art artifact, rootDepManagement []pomDependency) (analysisResult, error) {
|
||||
func (p *Parser) resolve(ctx context.Context, art artifact, rootDepManagement []pomDependency, isImportedArt bool) (analysisResult, error) {
|
||||
cache := p.cache
|
||||
if isImportedArt {
|
||||
cache = p.importCache
|
||||
}
|
||||
|
||||
// If the artifact is found in cache, it is returned.
|
||||
if result := p.cache.get(art); result != nil {
|
||||
if result := cache.get(art); result != nil {
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
@@ -453,16 +463,21 @@ func (p *Parser) resolve(ctx context.Context, art artifact, rootDepManagement []
|
||||
}
|
||||
|
||||
result, err := p.analyze(ctx, pomContent, analysisOptions{
|
||||
exclusions: art.Exclusions,
|
||||
depManagement: rootDepManagement,
|
||||
rootFilePath: art.RootFilePath,
|
||||
repositories: art.Repositories,
|
||||
exclusions: art.Exclusions,
|
||||
depManagement: rootDepManagement,
|
||||
rootFilePath: art.RootFilePath,
|
||||
repositories: art.Repositories,
|
||||
skipDependencies: isImportedArt,
|
||||
})
|
||||
if err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("analyze error: %w", err)
|
||||
}
|
||||
|
||||
p.cache.put(art, result)
|
||||
// As in Maven, an imported (from depManagement) POM that was not found is not cached,
|
||||
// because another POM importing it may declare other repositories where it can be found.
|
||||
if pomContent != nil || !isImportedArt {
|
||||
cache.put(art, result)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -476,10 +491,11 @@ type analysisResult struct {
|
||||
}
|
||||
|
||||
type analysisOptions struct {
|
||||
exclusions set.Set[string]
|
||||
depManagement []pomDependency // from the root POM
|
||||
rootFilePath string // File path of the root POM or module POM
|
||||
repositories []repository // Repositories inherited from parent
|
||||
exclusions set.Set[string]
|
||||
depManagement []pomDependency // from the root POM
|
||||
rootFilePath string // File path of the root POM or module POM
|
||||
repositories []repository // Repositories from upper-level POMs
|
||||
skipDependencies bool // skipDependencies skips resolving dependencies, e.g. for POMs imported into dependencyManagement
|
||||
}
|
||||
|
||||
func (p *Parser) analyze(ctx context.Context, pom *pom, opts analysisOptions) (analysisResult, error) {
|
||||
@@ -490,30 +506,37 @@ func (p *Parser) analyze(ctx context.Context, pom *pom, opts analysisOptions) (a
|
||||
opts.exclusions = set.New[string]()
|
||||
}
|
||||
|
||||
// Get repositories from current POM and merge with inherited ones
|
||||
pomRepos := pom.repositories(p.servers)
|
||||
opts.repositories = lo.UniqBy(append(pomRepos, opts.repositories...), func(r repository) url.URL {
|
||||
return r.url
|
||||
})
|
||||
|
||||
// Resolve parent POM
|
||||
// TODO handle repos from parents
|
||||
if err := p.resolveParent(ctx, pom, opts.repositories); err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("pom resolve error: %w", err)
|
||||
}
|
||||
|
||||
// Repositories of this POM, including the ones from its parent POMs
|
||||
pomRepos := pom.repositories(p.servers)
|
||||
|
||||
// As in Maven, repositories of this POM take precedence over the ones with the same ID from upper-level POMs
|
||||
// when resolving the POMs it imports, but not when resolving its dependencies.
|
||||
// cf. https://github.com/apache/maven/blob/maven-3.9.9/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java#L402
|
||||
// cf. https://github.com/apache/maven-resolver/blob/maven-resolver-1.9.22/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/df/DfDependencyCollector.java#L329-L332
|
||||
importRepos := mergeRepositories(pomRepos, opts.repositories)
|
||||
opts.repositories = mergeRepositories(opts.repositories, pomRepos)
|
||||
|
||||
// Resolve dependencies
|
||||
props := pom.properties()
|
||||
depManagement := pom.content.DependencyManagement.Dependencies.Dependency
|
||||
deps, err := p.parseDependencies(ctx, pom.content.Dependencies.Dependency, props, depManagement, opts)
|
||||
if err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("unable to parse dependencies: %w", err)
|
||||
var deps []artifact
|
||||
if !opts.skipDependencies {
|
||||
var err error
|
||||
deps, err = p.parseDependencies(ctx, pom.content.Dependencies.Dependency, props, depManagement, importRepos, opts)
|
||||
if err != nil {
|
||||
return analysisResult{}, xerrors.Errorf("unable to parse dependencies: %w", err)
|
||||
}
|
||||
deps = p.filterDependencies(deps, opts.exclusions)
|
||||
}
|
||||
deps = p.filterDependencies(deps, opts.exclusions)
|
||||
|
||||
art := pom.artifact()
|
||||
art.RootFilePath = opts.rootFilePath
|
||||
art.Repositories = opts.repositories
|
||||
art.Repositories = importRepos // used to resolve the POMs imported by this POM
|
||||
|
||||
return analysisResult{
|
||||
filePath: pom.filePath,
|
||||
@@ -532,6 +555,9 @@ func (p *Parser) resolveParent(ctx context.Context, pom *pom, pomRepos []reposit
|
||||
}
|
||||
|
||||
// Parse parent POM
|
||||
// The parent POM is also searched in the repositories of this POM.
|
||||
// Repositories from child POMs take precedence over parent repositories with the same ID.
|
||||
pomRepos = mergeRepositories(pomRepos, pom.repositories(p.servers))
|
||||
parent, err := p.parseParent(ctx, pom.filePath, pom.content.Parent, pomRepos)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("parent error: %w", err)
|
||||
@@ -555,6 +581,10 @@ func (p *Parser) resolveParent(ctx context.Context, pom *pom, pomRepos []reposit
|
||||
pom.content.Dependencies.Dependency,
|
||||
parent.content.Dependencies.Dependency)
|
||||
|
||||
// Merge repositories.
|
||||
// A repository disabled in this POM also hides the one with the same ID from the parent POM.
|
||||
pom.content.Repositories = mergePomRepositories(pom.content.Repositories, parent.content.Repositories)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -575,7 +605,7 @@ func (p *Parser) mergeDependencyManagements(depManagements ...[]pomDependency) [
|
||||
}
|
||||
|
||||
func (p *Parser) parseDependencies(ctx context.Context, deps []pomDependency, props map[string]string, depManagement []pomDependency,
|
||||
opts analysisOptions,
|
||||
importRepos []repository, opts analysisOptions,
|
||||
) ([]artifact, error) {
|
||||
// Imported POMs often have no dependencies, so dependencyManagement resolution can be skipped.
|
||||
if len(deps) == 0 {
|
||||
@@ -584,7 +614,7 @@ func (p *Parser) parseDependencies(ctx context.Context, deps []pomDependency, pr
|
||||
|
||||
var err error
|
||||
// Resolve dependencyManagement
|
||||
depManagement, err = p.resolveDepManagement(ctx, props, depManagement)
|
||||
depManagement, err = p.resolveDepManagement(ctx, props, depManagement, importRepos, set.New[string]())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("unable to resolve dep management: %w", err)
|
||||
}
|
||||
@@ -606,9 +636,16 @@ func (p *Parser) parseDependencies(ctx context.Context, deps []pomDependency, pr
|
||||
|
||||
// resolveDepManagement resolves depManagement, including imported POMs.
|
||||
// It returns resolved depManagement with variables evaluated.
|
||||
// imported tracks POMs in the current chain of imports to break import cycles.
|
||||
// As in Maven, a POM is removed from it after its import is resolved,
|
||||
// so a previously not found POM can be resolved again when imported by another POM
|
||||
// (e.g. with other repositories).
|
||||
// cf. https://github.com/apache/maven/blob/maven-3.9.9/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java#L1259
|
||||
// It continues to resolve even if an error occurs while resolving an imported POM,
|
||||
// but it returns an error if a context is canceled or the deadline is exceeded.
|
||||
func (p *Parser) resolveDepManagement(ctx context.Context, props map[string]string, depManagement []pomDependency) ([]pomDependency, error) {
|
||||
func (p *Parser) resolveDepManagement(ctx context.Context, props map[string]string, depManagement []pomDependency,
|
||||
repos []repository, imported set.Set[string],
|
||||
) ([]pomDependency, error) {
|
||||
var newDepManagement, imports []pomDependency
|
||||
for _, dep := range depManagement {
|
||||
// cf. https://howtodoinjava.com/maven/maven-dependency-scopes/#import
|
||||
@@ -624,20 +661,34 @@ func (p *Parser) resolveDepManagement(ctx context.Context, props map[string]stri
|
||||
// cf. https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#importing-dependencies
|
||||
for _, imp := range imports {
|
||||
art := newArtifact(imp.GroupID, imp.ArtifactID, imp.Version, nil, props)
|
||||
result, err := p.resolve(ctx, art, nil)
|
||||
if imported.Contains(art.String()) {
|
||||
p.logger.Debug("Skipping import cycle", log.String("artifact", art.String()))
|
||||
continue
|
||||
}
|
||||
imported.Append(art.String())
|
||||
art.Repositories = slices.Clone(repos) // avoid sharing
|
||||
|
||||
// As in Maven, only dependencyManagement of the imported POM is used,
|
||||
// so its dependencies, including ones inherited from parent POMs, are not resolved.
|
||||
// Resolving them would resolve their dependencyManagement and could import the same POM again,
|
||||
// bypassing the check for import cycles.
|
||||
// cf. https://github.com/apache/maven/blob/maven-3.9.9/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java#L1241
|
||||
result, err := p.resolve(ctx, art, nil, true)
|
||||
if shouldReturnError(err) {
|
||||
return nil, err
|
||||
} else if err != nil {
|
||||
} else if err != nil || result.artifact.IsEmpty() {
|
||||
imported.Remove(art.String())
|
||||
continue
|
||||
}
|
||||
|
||||
// We need to recursively check all nested depManagements,
|
||||
// so that we don't miss dependencies on nested depManagements with `Import` scope.
|
||||
newProps := utils.MergeMaps(props, result.properties)
|
||||
result.dependencyManagement, err = p.resolveDepManagement(ctx, newProps, result.dependencyManagement)
|
||||
result.dependencyManagement, err = p.resolveDepManagement(ctx, newProps, result.dependencyManagement, result.artifact.Repositories, imported)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imported.Remove(art.String())
|
||||
for k, dd := range result.dependencyManagement {
|
||||
// Evaluate variables and overwrite dependencyManagement
|
||||
result.dependencyManagement[k] = dd.Resolve(newProps, nil, nil)
|
||||
@@ -657,6 +708,30 @@ func (p *Parser) mergeDependencies(child, parent []pomDependency) []pomDependenc
|
||||
})
|
||||
}
|
||||
|
||||
// mergeRepositories merges repositories in order of priority and removes repositories with duplicate IDs.
|
||||
// Repositories without an ID are deduplicated by URL.
|
||||
func mergeRepositories(repos ...[]repository) []repository {
|
||||
return lo.UniqBy(slices.Concat(repos...), func(r repository) string {
|
||||
// Maven requires the repository ID, so fall back to the URL to keep repositories without one
|
||||
if r.id == "" {
|
||||
return r.url.String()
|
||||
}
|
||||
return r.id
|
||||
})
|
||||
}
|
||||
|
||||
// mergePomRepositories merges repository declarations of a child POM and its parent POM by ID, the child taking precedence.
|
||||
// cf. https://github.com/apache/maven/blob/maven-3.9.9/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java#L237
|
||||
func mergePomRepositories(child, parent []pomRepository) []pomRepository {
|
||||
return lo.UniqBy(slices.Concat(child, parent), func(r pomRepository) string {
|
||||
// Maven requires the repository ID, so fall back to the URL to keep repositories without one
|
||||
if r.ID == "" {
|
||||
return r.URL
|
||||
}
|
||||
return r.ID
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Parser) filterDependencies(artifacts []artifact, exclusions set.Set[string]) []artifact {
|
||||
return lo.Filter(artifacts, func(art artifact, _ int) bool {
|
||||
return !excludeDep(exclusions, art)
|
||||
@@ -873,6 +948,17 @@ func (p *Parser) fetchPOMFromRemoteRepositories(ctx context.Context, paths []str
|
||||
}
|
||||
seen.Append(candidate.url.String())
|
||||
|
||||
// As in Maven Resolver, a POM that a repository did not serve is not requested from it again.
|
||||
// cf. https://github.com/apache/maven-resolver/blob/maven-resolver-1.9.22/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManager.java#L183
|
||||
// Maven Resolver also remembers transfer errors, and Maven fails the build on them. Trivy
|
||||
// continues resolution without the POM instead, so only 4xx responses other than 429 are
|
||||
// remembered, while 429 and 5xx responses and network errors are not, and a later lookup can
|
||||
// succeed once the repository recovers.
|
||||
notFoundKey := candidate.url.String() + "|" + path.Join(paths...)
|
||||
if p.notFoundPOMs.Contains(notFoundKey) {
|
||||
continue
|
||||
}
|
||||
|
||||
repoPaths := slices.Clone(paths) // Clone slice to avoid overwriting last element of `paths`
|
||||
if snapshot {
|
||||
pomFileName, err := p.fetchPomFileNameFromMavenMetadata(ctx, candidate, repoPaths)
|
||||
@@ -889,13 +975,17 @@ func (p *Parser) fetchPOMFromRemoteRepositories(ctx context.Context, paths []str
|
||||
}
|
||||
}
|
||||
fetched, err := p.fetchPOMFromRemoteRepository(ctx, candidate, repoPaths)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, errPOMNotFound):
|
||||
p.notFoundPOMs.Append(notFoundKey)
|
||||
continue
|
||||
case err != nil:
|
||||
if target, ok := errors.AsType[*rateLimitTarget](err); ok {
|
||||
rateLimitTargets = append(rateLimitTargets, *target)
|
||||
continue
|
||||
}
|
||||
return nil, wrapWithRateLimitTargets(xerrors.Errorf("fetch repository error: %w", err), rateLimitTargets)
|
||||
} else if fetched == nil {
|
||||
case fetched == nil:
|
||||
continue
|
||||
}
|
||||
return fetched, nil
|
||||
@@ -995,6 +1085,11 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(ctx context.Context, repo rep
|
||||
return pomFileName, nil
|
||||
}
|
||||
|
||||
// errPOMNotFound is returned when a repository answers with a 4xx response other than 429 for the POM, such as 404 or 403, which is not expected to change on a later request.
|
||||
var errPOMNotFound = xerrors.New("the POM was not found in the repository")
|
||||
|
||||
// fetchPOMFromRemoteRepository fetches the POM from the repository.
|
||||
// It returns errPOMNotFound for a 4xx response other than 429, and a nil POM without an error for failures that may not persist, such as a 5xx response or a network error.
|
||||
func (p *Parser) fetchPOMFromRemoteRepository(ctx context.Context, repo repository, paths []string) (*pom, error) {
|
||||
req, err := p.remoteRepoRequest(ctx, repo.url, paths)
|
||||
if err != nil {
|
||||
@@ -1017,6 +1112,9 @@ func (p *Parser) fetchPOMFromRemoteRepository(ctx context.Context, repo reposito
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
p.logUnexpectedStatus(repo, req.URL, resp.StatusCode)
|
||||
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError {
|
||||
return nil, errPOMNotFound
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/samber/lo"
|
||||
@@ -2551,7 +2553,8 @@ func TestPom_Parse_Remote_Repos(t *testing.T) {
|
||||
inputFile string
|
||||
rootRepoTxtar string // txtar file for root repository
|
||||
repos map[string]string // key: repository URL placeholder, value: txtar file path
|
||||
wantPackages map[string]string
|
||||
unusedRepos []string // repository URL placeholders that must not receive any requests
|
||||
wantPackages map[string]string // key: package name and version, value: license; empty if the POM must not be found
|
||||
}{
|
||||
{
|
||||
name: "different repos for different dependencies",
|
||||
@@ -2562,9 +2565,9 @@ func TestPom_Parse_Remote_Repos(t *testing.T) {
|
||||
"REPO2_URL": filepath.Join("testdata", "different-repos-for-different-poms", "repo2-artifacts.txtar"),
|
||||
},
|
||||
wantPackages: map[string]string{
|
||||
"org.example:example-api:1.7.30::2cbe1ca4": "License from repo1",
|
||||
"org.example:example-api2:1.0.0::f8958ec7": "License from repo2",
|
||||
"org.example:example-api3:1.0.0::887fc940": "License from reporoot",
|
||||
"org.example:example-api:1.7.30": "License from repo1",
|
||||
"org.example:example-api2:1.0.0": "License from repo2",
|
||||
"org.example:example-api3:1.0.0": "License from reporoot",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -2573,7 +2576,109 @@ func TestPom_Parse_Remote_Repos(t *testing.T) {
|
||||
rootRepoTxtar: filepath.Join("testdata", "repo-from-root-for-dep-from-module", "repo-artifacts.txtar"),
|
||||
repos: nil,
|
||||
wantPackages: map[string]string{
|
||||
"org.example:example-api:1.0.0::4a790a84": "License from root repo",
|
||||
"org.example:example-api:1.0.0": "License from root repo",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "imported BOMs are fetched from repositories of the importing POM, import cycles are skipped",
|
||||
inputFile: filepath.Join("testdata", "import-bom-from-pom-repos", "pom.xml"),
|
||||
rootRepoTxtar: filepath.Join("testdata", "import-bom-from-pom-repos", "repo-root-artifacts.txtar"),
|
||||
repos: map[string]string{
|
||||
"REPO1_URL": filepath.Join("testdata", "import-bom-from-pom-repos", "repo1-artifacts.txtar"),
|
||||
"REPO2_URL": filepath.Join("testdata", "import-bom-from-pom-repos", "repo2-artifacts.txtar"),
|
||||
},
|
||||
wantPackages: map[string]string{
|
||||
// version from the BOM in the root POM repository
|
||||
"org.example:example-api:1.1.0": "License from reporoot",
|
||||
// version from the nested BOM in the repository of the imported BOM
|
||||
"org.example:example-api-nested:1.2.0": "License from reporoot",
|
||||
// version from the BOM imported by two BOMs, found only in the repository of the second one
|
||||
"org.example:example-api-shared:1.4.0": "License from reporoot",
|
||||
// version from the BOM in the repository of the transitive dependency
|
||||
"org.example:example-api-transitive:1.3.0": "License from repo2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repositories are inherited from parent POMs and overridden by ID",
|
||||
inputFile: filepath.Join("testdata", "repos-from-parent-poms", "pom.xml"),
|
||||
rootRepoTxtar: filepath.Join("testdata", "repos-from-parent-poms", "repo-root-artifacts.txtar"),
|
||||
repos: map[string]string{
|
||||
"REPO1_URL": filepath.Join("testdata", "repos-from-parent-poms", "repo1-artifacts.txtar"),
|
||||
"REPO2_URL": filepath.Join("testdata", "repos-from-parent-poms", "repo2-artifacts.txtar"),
|
||||
"REPO3_URL": filepath.Join("testdata", "repos-from-parent-poms", "repo3-artifacts.txtar"),
|
||||
"REPO4_URL": filepath.Join("testdata", "repos-from-parent-poms", "repo4-artifacts.txtar"),
|
||||
},
|
||||
// overridden and disabled by the child POM
|
||||
unusedRepos: []string{"REPO2_URL", "REPO3_URL"},
|
||||
wantPackages: map[string]string{
|
||||
// version from the BOM in the repository of the parent POM
|
||||
"org.example:example-api:1.1.0": "License from repo1",
|
||||
// version from the grandparent POM in the repository of the parent POM
|
||||
"org.example:example-api2:1.0.0": "License from repo1",
|
||||
// repositories of the POM take precedence over the ones inherited from the parent POM
|
||||
"org.example:example-api3:1.0.0": "License from reporoot",
|
||||
// the parent repository is overridden by the child repository with the same ID
|
||||
"org.example:example-api4:1.0.0": "",
|
||||
// the parent repository is disabled by the child repository with the same ID
|
||||
"org.example:example-api5:1.0.0": "",
|
||||
// version from the greatgrandparent POM in the child's overridden repository
|
||||
"org.example:example-api6:1.0.0-reporoot": "License from reporoot",
|
||||
// the version from the ancestor in the child's disabled repository is not resolved,
|
||||
// so example-api7 is skipped (checked by requests to unusedRepos)
|
||||
// the parent repository without an ID is kept along with the child repository without an ID
|
||||
"org.example:example-api8:1.0.0": "License from repo4",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repositories disabled in child POMs hide the ones with the same ID while resolving ancestors",
|
||||
inputFile: filepath.Join("testdata", "disabled-repos-hide-ancestor-repos", "pom.xml"),
|
||||
rootRepoTxtar: filepath.Join("testdata", "disabled-repos-hide-ancestor-repos", "repo-root-artifacts.txtar"),
|
||||
repos: map[string]string{
|
||||
"REPO_DISABLED_URL": filepath.Join("testdata", "disabled-repos-hide-ancestor-repos", "repo-disabled-artifacts.txtar"),
|
||||
},
|
||||
// declared in the parent POMs, but disabled (fully or for releases) in the scanned POM or the dependency POM
|
||||
unusedRepos: []string{"REPO_DISABLED_URL"},
|
||||
wantPackages: map[string]string{
|
||||
// version from the parent POM of the scanned POM
|
||||
"org.example:example-api:1.0.0": "License from reporoot",
|
||||
"org.example:example-dep:1.0.0": "License from reporoot",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repositories of the scanned POM take precedence over the ones with the same ID from dependency POMs",
|
||||
inputFile: filepath.Join("testdata", "dependency-repos-do-not-override-context", "pom.xml"),
|
||||
rootRepoTxtar: filepath.Join("testdata", "dependency-repos-do-not-override-context", "repo-root-artifacts.txtar"),
|
||||
repos: map[string]string{
|
||||
"REPO_OLD_URL": filepath.Join("testdata", "dependency-repos-do-not-override-context", "repo-old-artifacts.txtar"),
|
||||
"REPO_DISABLED_URL": filepath.Join("testdata", "dependency-repos-do-not-override-context", "repo-disabled-artifacts.txtar"),
|
||||
},
|
||||
// declared in the dependency POM, but disabled in the scanned POM
|
||||
unusedRepos: []string{"REPO_DISABLED_URL"},
|
||||
wantPackages: map[string]string{
|
||||
"org.example:example-dep:1.0.0": "License from reporoot",
|
||||
// version from the BOM in the dependency POM's repository
|
||||
"org.example:example-mid:1.0.0": "License from reporoot",
|
||||
// declared in the transitive dependency, found in the scanned POM's repository with the same ID
|
||||
"org.example:example-leaf:1.0.0": "License from reporoot",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repositories of the aggregator POM are not used for modules that do not inherit from it",
|
||||
inputFile: filepath.Join("testdata", "aggregator-repos-not-used-for-modules", "pom.xml"),
|
||||
rootRepoTxtar: filepath.Join("testdata", "aggregator-repos-not-used-for-modules", "repo-root-artifacts.txtar"),
|
||||
repos: map[string]string{
|
||||
"REPO_AGGREGATOR_URL": filepath.Join("testdata", "aggregator-repos-not-used-for-modules", "repo-aggregator-artifacts.txtar"),
|
||||
"REPO_AGGREGATOR_OTHER_URL": filepath.Join("testdata", "aggregator-repos-not-used-for-modules", "repo-aggregator-other-artifacts.txtar"),
|
||||
},
|
||||
// declared only in the aggregator POM, which is not the parent of the module
|
||||
unusedRepos: []string{"REPO_AGGREGATOR_URL", "REPO_AGGREGATOR_OTHER_URL"},
|
||||
wantPackages: map[string]string{
|
||||
// version from the parent POM in the module's repository
|
||||
"org.example:example-api:1.0.0": "License from reporoot",
|
||||
// version from the BOM in the module's repository
|
||||
"org.example:example-api2:1.0.0": "License from reporoot",
|
||||
// published only to a repository of the aggregator POM
|
||||
"org.example:example-api3:1.0.0": "",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -2582,33 +2687,50 @@ func TestPom_Parse_Remote_Repos(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Setup remote repositories from txtar files
|
||||
repoURLs := make(map[string]string)
|
||||
repoRequests := make(map[string]*atomic.Int64)
|
||||
for placeholder, txtarPath := range tt.repos {
|
||||
repoURL := setupTxtarRepository(t, txtarPath, nil)
|
||||
repoURLs[placeholder] = repoURL
|
||||
repoURLs[placeholder], repoRequests[placeholder] = setupTxtarRepository(t, txtarPath, nil)
|
||||
}
|
||||
|
||||
// Setup root repository with replacements for repo placeholders
|
||||
rootRepoURL := setupTxtarRepository(t, tt.rootRepoTxtar, repoURLs)
|
||||
rootRepoURL, _ := setupTxtarRepository(t, tt.rootRepoTxtar, repoURLs)
|
||||
|
||||
// Prepare input POM file with root repository URL
|
||||
pomContent := applyReplacements(t, tt.inputFile, map[string]string{
|
||||
rootRepoPlaceholder: rootRepoURL,
|
||||
})
|
||||
// Copy the directory of the input POM file with repository URLs, so that modules can declare repositories too
|
||||
replacements := maps.Clone(repoURLs)
|
||||
replacements[rootRepoPlaceholder] = rootRepoURL
|
||||
inputDir := copyWithReplacements(t, filepath.Dir(tt.inputFile), replacements)
|
||||
inputFile := filepath.Join(inputDir, filepath.Base(tt.inputFile))
|
||||
pomContent, err := os.ReadFile(inputFile)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Default repository that always returns 404 to ensure remote tests don't reach Maven Central
|
||||
dummyServer := httptest.NewServer(http.NotFoundHandler())
|
||||
t.Cleanup(dummyServer.Close)
|
||||
|
||||
// Parse the POM
|
||||
parser := pom.NewParser(tt.inputFile)
|
||||
parser := pom.NewParser(inputFile, pom.WithDefaultRepo(dummyServer.URL, true, true))
|
||||
pkgs, _, err := parser.Parse(t.Context(), bytes.NewReader(pomContent))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify expected packages
|
||||
for pkgID, wantLicense := range tt.wantPackages {
|
||||
p, found := lo.Find(pkgs, func(pkg ftypes.Package) bool {
|
||||
return pkg.ID == pkgID
|
||||
// Verify expected packages.
|
||||
// Package IDs depend on the path of the temporary directory, so packages are matched by name and version.
|
||||
for pkgName, wantLicense := range tt.wantPackages {
|
||||
found := lo.Filter(pkgs, func(pkg ftypes.Package, _ int) bool {
|
||||
return pkg.Name+":"+pkg.Version == pkgName
|
||||
})
|
||||
require.True(t, found, "package %s not found", pkgID)
|
||||
require.NotEmpty(t, p.Licenses, "package %s has no licenses", pkgID)
|
||||
require.Len(t, found, 1, "package %s", pkgName)
|
||||
p := found[0]
|
||||
if wantLicense == "" {
|
||||
require.Empty(t, p.Licenses, "package %s has licenses", pkgName)
|
||||
continue
|
||||
}
|
||||
require.NotEmpty(t, p.Licenses, "package %s has no licenses", pkgName)
|
||||
require.Equal(t, wantLicense, p.Licenses[0])
|
||||
}
|
||||
|
||||
for _, placeholder := range tt.unusedRepos {
|
||||
assert.Zero(t, repoRequests[placeholder].Load(), "repository %s was requested", placeholder)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2627,6 +2749,31 @@ func applyReplacements(t *testing.T, filePath string, replacements map[string]st
|
||||
return content
|
||||
}
|
||||
|
||||
// copyWithReplacements copies the directory to a temporary directory, applies replacements to the copied files
|
||||
// and returns the temporary directory.
|
||||
func copyWithReplacements(t *testing.T, dir string, replacements map[string]string) string {
|
||||
t.Helper()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
return err
|
||||
}
|
||||
rel, err := filepath.Rel(dir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst := filepath.Join(tmpDir, rel)
|
||||
if err = os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(dst, applyReplacements(t, path, replacements), 0o600)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
return tmpDir
|
||||
}
|
||||
|
||||
// txtarWithReposReplace reads a txtar file, applies repository URL replacements,
|
||||
// and returns the result as a fs.FS.
|
||||
func txtarWithReposReplace(t *testing.T, txtarPath string, reposReplacements map[string]string) fs.FS {
|
||||
@@ -2643,16 +2790,21 @@ func txtarWithReposReplace(t *testing.T, txtarPath string, reposReplacements map
|
||||
}
|
||||
|
||||
// setupTxtarRepository reads a txtar file, applies repository URL replacements,
|
||||
// starts an HTTP test server with the files, and returns the server URL.
|
||||
func setupTxtarRepository(t *testing.T, txtarPath string, reposReplacements map[string]string) string {
|
||||
// starts an HTTP test server with the files, and returns the server URL and the number of requests to it.
|
||||
func setupTxtarRepository(t *testing.T, txtarPath string, reposReplacements map[string]string) (string, *atomic.Int64) {
|
||||
t.Helper()
|
||||
|
||||
fsys := txtarWithReposReplace(t, txtarPath, reposReplacements)
|
||||
|
||||
ts := httptest.NewServer(http.FileServer(http.FS(fsys)))
|
||||
requests := &atomic.Int64{}
|
||||
fileServer := http.FileServer(http.FS(fsys))
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests.Add(1)
|
||||
fileServer.ServeHTTP(w, r)
|
||||
}))
|
||||
t.Cleanup(ts.Close)
|
||||
|
||||
return ts.URL
|
||||
return ts.URL, requests
|
||||
}
|
||||
|
||||
func TestPomLicenseName(t *testing.T) {
|
||||
|
||||
@@ -37,6 +37,7 @@ var mavenCentralRepo = repository{
|
||||
releaseEnabled: true,
|
||||
}
|
||||
|
||||
// resolvePomRepos also returns disabled repositories, so that they hide repositories with the same ID, as in Maven.
|
||||
func resolvePomRepos(servers []Server, pomRepos []pomRepository) []repository {
|
||||
logger := log.WithPrefix("pom")
|
||||
var repos []repository
|
||||
@@ -49,11 +50,6 @@ func resolvePomRepos(servers []Server, pomRepos []pomRepository) []repository {
|
||||
snapshotEnabled: rep.SnapshotsEnabled == trueString || rep.SnapshotsEnabled == "",
|
||||
}
|
||||
|
||||
// Add only enabled repositories
|
||||
if !r.releaseEnabled && !r.snapshotEnabled {
|
||||
continue
|
||||
}
|
||||
|
||||
repoURL, err := url.Parse(rep.URL)
|
||||
if err != nil {
|
||||
if ue, ok := errors.AsType[*url.Error](err); ok {
|
||||
@@ -62,6 +58,10 @@ func resolvePomRepos(servers []Server, pomRepos []pomRepository) []repository {
|
||||
logger.Debug("Unable to parse remote repository url", log.String("id", rep.ID), log.Err(err))
|
||||
continue
|
||||
}
|
||||
if !repoURL.IsAbs() {
|
||||
logger.Debug("Remote repository url must be absolute", log.String("id", rep.ID))
|
||||
continue
|
||||
}
|
||||
|
||||
// Get the credentials from settings.xml based on matching server id
|
||||
// with the repository id from pom.xml and use it for accessing the repository url
|
||||
@@ -72,7 +72,8 @@ func resolvePomRepos(servers []Server, pomRepos []pomRepository) []repository {
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debug("Adding repository", log.String("id", rep.ID), log.String("url", repoURL.Redacted()))
|
||||
logger.Debug("Adding repository", log.String("id", rep.ID), log.String("url", repoURL.Redacted()),
|
||||
log.Bool("releases", r.releaseEnabled), log.Bool("snapshots", r.snapshotEnabled))
|
||||
r.url = *repoURL
|
||||
repos = append(repos, r)
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ func Test_effectiveRepositories(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "disabled repositories are ignored",
|
||||
name: "disabled repositories are kept",
|
||||
s: settings{
|
||||
Profiles: []Profile{
|
||||
{
|
||||
@@ -625,6 +625,7 @@ func Test_effectiveRepositories(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
// Reversed, as Maven takes repositories from settings in reverse order
|
||||
want: []repository{
|
||||
{
|
||||
id: "enabled",
|
||||
@@ -632,6 +633,41 @@ func Test_effectiveRepositories(t *testing.T) {
|
||||
releaseEnabled: true,
|
||||
snapshotEnabled: false,
|
||||
},
|
||||
{
|
||||
id: "disabled",
|
||||
url: mustParseURL(t, "https://example.com/disabled"),
|
||||
releaseEnabled: false,
|
||||
snapshotEnabled: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repositories with relative URLs are skipped",
|
||||
s: settings{
|
||||
Profiles: []Profile{
|
||||
{
|
||||
ID: "p",
|
||||
ActiveByDefault: true,
|
||||
Repositories: []pomRepository{
|
||||
{
|
||||
ID: "relative",
|
||||
URL: "repo/relative",
|
||||
},
|
||||
{
|
||||
ID: "absolute",
|
||||
URL: "https://example.com/absolute",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []repository{
|
||||
{
|
||||
id: "absolute",
|
||||
url: mustParseURL(t, "https://example.com/absolute"),
|
||||
releaseEnabled: true,
|
||||
snapshotEnabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!-- the module doesn't inherit from the aggregator -->
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>company-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<artifactId>module</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- version from the parent POM -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
</dependency>
|
||||
<!-- version from the BOM -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
</dependency>
|
||||
<!-- published only to a repository of the aggregator POM, so it is not found -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>aggregator</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<!-- the module declares the same ID with another URL -->
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_AGGREGATOR_URL</url>
|
||||
</repository>
|
||||
<!-- the module declares no repository with this ID -->
|
||||
<repository>
|
||||
<id>aggregator-other</id>
|
||||
<url>REPO_AGGREGATOR_OTHER_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<modules>
|
||||
<module>module</module>
|
||||
</modules>
|
||||
</project>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
Aggregator repository (declared in the aggregator as "corp", which the module declares with another URL): must not be used for the module, which doesn't inherit from the aggregator POM.
|
||||
|
||||
-- org/example/company-parent/1.0.0/company-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>company-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Another repository of the aggregator POM (the module declares no repository with this ID): must not be used for the module either.
|
||||
|
||||
-- org/example/example-api3/1.0.0/example-api3-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repoaggregatorother</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
Root repository (declared in the module as "corp", which the aggregator declares with another URL): the parent POM of the module, the BOM imported by the module and its dependencies.
|
||||
|
||||
-- org/example/company-parent/1.0.0/company-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>company-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-bom/1.0.0/example-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api/1.0.0/example-api-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api2/1.0.0/example-api2-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>dependency-repos-do-not-override-context</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<repositories>
|
||||
<!-- the dependency POM declares the same ID with another URL -->
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
<!-- the dependency POM declares the same ID, which must stay disabled -->
|
||||
<repository>
|
||||
<id>corp-disabled</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Disabled repository (declared in the dependency POM as "corp-disabled", which the scanned POM disables): must not be used.
|
||||
|
||||
-- org/example/example-mid/1.0.0/example-mid-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-mid</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repodisabled</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
Old repository (declared in the dependency POM as "corp", which the scanned POM declares with another URL): only the BOM imported by the dependency.
|
||||
The dependency POM's own imports are resolved from its repositories, while its dependencies are resolved from the scanned POM's "corp".
|
||||
|
||||
-- org/example/example-bom/1.0.0/example-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-mid</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
Root repository (declared in the scanned POM as "corp"): the dependency and its transitive dependencies.
|
||||
The dependency POM declares "corp" with the URL of the old repository and "corp-disabled", which is disabled in the scanned POM.
|
||||
|
||||
-- org/example/example-dep/1.0.0/example-dep-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_OLD_URL</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>corp-disabled</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- published only to the old repository -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- version from the BOM -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-mid</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
-- org/example/example-mid/1.0.0/example-mid-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-mid</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-leaf</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
-- org/example/example-leaf/1.0.0/example-leaf-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-leaf</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>disabled-repos-hide-ancestor-repos</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>root-repo</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
<!-- disables the repository with the same ID declared in the parent POM -->
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<!-- disables releases only, which also hides the release repository with the same ID declared in the parent POM -->
|
||||
<repository>
|
||||
<id>corp-releases</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- version from the parent POM -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
Disabled repository (declared in the parent POMs, disabled by ID in their child POMs): the grandparent POMs, which must not be fetched from it.
|
||||
|
||||
-- org/example/example-grandparent/1.0.0/example-grandparent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
||||
|
||||
-- org/example/example-dep-grandparent/1.0.0/example-dep-grandparent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
||||
pkg/dependency/parser/java/pom/testdata/disabled-repos-hide-ancestor-repos/repo-root-artifacts.txtar
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
Root repository: the parent POMs of the scanned POM and of its dependency, and the dependency managed by the parent POM.
|
||||
The parent POMs declare the repositories disabled in the scanned POM or the dependency POM, where their own parent POMs are published.
|
||||
The dependency has no dependencies, so its repositories are only used to resolve its parent POMs.
|
||||
|
||||
-- org/example/example-parent/1.0.0/example-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>example-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>corp-releases</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api/1.0.0/example-api-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-dep/1.0.0/example-dep-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>example-dep</artifactId>
|
||||
|
||||
<repositories>
|
||||
<!-- disables the repository with the same ID declared in the parent POM -->
|
||||
<repository>
|
||||
<id>dep-corp</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-dep-parent/1.0.0/example-dep-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dep-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>example-dep-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<!-- disabled in the scanned POM -->
|
||||
<repository>
|
||||
<id>corp</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
</repository>
|
||||
<!-- disabled in the child POM -->
|
||||
<repository>
|
||||
<id>dep-corp</id>
|
||||
<url>REPO_DISABLED_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
@@ -0,0 +1,63 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>import-bom-from-pom-repos</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>root-repo</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- imports example-shared-bom, which is also imported by example-bom, but found only in the repositories of this BOM -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-sibling-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- not found in the repositories of this POM, but found in the repositories of example-dependency -->
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-nested</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-shared</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
Vendored
+165
@@ -0,0 +1,165 @@
|
||||
Root repository: the BOMs imported by the root POM, the transitive dependency and the libraries managed for the root POM.
|
||||
Both BOMs import example-shared-bom, which is found only in repository 2 declared by example-sibling-bom.
|
||||
|
||||
-- org/example/example-bom/1.0.0/example-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo1</id>
|
||||
<url>REPO1_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-nested-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-shared-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-sibling-bom/1.0.0/example-sibling-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-sibling-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo2</id>
|
||||
<url>REPO2_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-shared-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api-shared/1.4.0/example-api-shared-1.4.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-shared</artifactId>
|
||||
<version>1.4.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-dependency/1.0.0/example-dependency-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo2</id>
|
||||
<url>REPO2_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-transitive</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api/1.1.0/example-api-1.1.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api-nested/1.2.0/example-api-nested-1.2.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-nested</artifactId>
|
||||
<version>1.2.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
Repository 1: the nested BOM imported by example-bom. It imports example-bom back to form an import cycle
|
||||
and has ordinary dependencies, which are not imported.
|
||||
|
||||
-- org/example/example-nested-bom/1.0.0/example-nested-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-nested-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-nested</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-nested</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
Repository 2: the BOM imported by example-dependency, its parent POM and its managed library, and the BOM shared by the BOMs of the root POM.
|
||||
The BOM imports itself and inherits ordinary dependencies from its parent POM, which are not imported.
|
||||
|
||||
-- org/example/example-dependency-bom/1.0.0/example-dependency-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency-bom-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>example-dependency-bom</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-transitive</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-dependency-bom-parent/1.0.0/example-dependency-bom-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-dependency-bom-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-transitive</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
-- org/example/example-shared-bom/1.0.0/example-shared-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-shared-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-shared</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api-transitive/1.3.0/example-api-transitive-1.3.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api-transitive</artifactId>
|
||||
<version>1.3.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo2</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>repos-from-parent-poms</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>root-repo</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
<!-- Maven requires the ID, but repositories without one are kept and deduplicated by URL -->
|
||||
<repository>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
<!-- overrides the repository with the same ID from the parent POM -->
|
||||
<repository>
|
||||
<id>overridden-repo</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
</repository>
|
||||
<!-- disables the repository with the same ID from the parent POM -->
|
||||
<repository>
|
||||
<id>disabled-repo</id>
|
||||
<url>REPO_ROOT_URL</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api4</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api5</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api6</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api7</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api8</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
Root repository: the parent POM and a dependency also published to repository 1.
|
||||
The parent POM also declares repositories 2 and 3, which the child POM overrides and disables by ID,
|
||||
and repository 4 without an ID, which is kept although the child POM also declares a repository without an ID.
|
||||
|
||||
-- org/example/example-parent/1.0.0/example-parent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>example-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo1</id>
|
||||
<url>REPO1_URL</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>overridden-repo</id>
|
||||
<url>REPO2_URL</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>disabled-repo</id>
|
||||
<url>REPO3_URL</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<url>REPO4_URL</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api3/1.0.0/example-api3-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-greatgrandparent/1.0.0/example-greatgrandparent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-disabled-ancestor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-greatgrandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api6</artifactId>
|
||||
<version>1.0.0-reporoot</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api6/1.0.0-reporoot/example-api6-1.0.0-reporoot.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api6</artifactId>
|
||||
<version>1.0.0-reporoot</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from reporoot</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
Repository 1 (declared in the parent POM): the grandparent POM, the imported BOM and the dependencies managed by them, one of which is also published to the root repository.
|
||||
|
||||
-- org/example/example-grandparent/1.0.0/example-grandparent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-greatgrandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-grandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-bom/1.0.0/example-bom-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-bom</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api2/1.0.0/example-api2-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api2</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo1</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api/1.1.0/example-api-1.1.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo1</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api3/1.0.0/example-api3-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo1</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
Repository 2 (declared in the parent POM, overridden by ID in the child POM): must not be used.
|
||||
|
||||
-- org/example/example-api4/1.0.0/example-api4-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api4</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo2</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-greatgrandparent/1.0.0/example-greatgrandparent-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-greatgrandparent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api6</artifactId>
|
||||
<version>1.0.0-repo2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api6/1.0.0-repo2/example-api6-1.0.0-repo2.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api6</artifactId>
|
||||
<version>1.0.0-repo2</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo2</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
Repository 3 (declared in the parent POM, disabled by ID in the child POM): must not be used.
|
||||
|
||||
-- org/example/example-api5/1.0.0/example-api5-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api5</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo3</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
|
||||
-- org/example/example-disabled-ancestor/1.0.0/example-disabled-ancestor-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-disabled-ancestor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api7</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
-- org/example/example-api7/1.0.0/example-api7-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api7</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo3</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Repository 4 (declared without an ID in the parent POM): a dependency of the child POM.
|
||||
|
||||
-- org/example/example-api8/1.0.0/example-api8-1.0.0.pom --
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>example-api8</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>License from repo4</name>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
@@ -18,7 +18,7 @@ func init() {
|
||||
analyzer.RegisterAnalyzer(&pomAnalyzer{})
|
||||
}
|
||||
|
||||
const version = 1
|
||||
const version = 2
|
||||
|
||||
// pomAnalyzer analyzes pom.xml
|
||||
type pomAnalyzer struct{}
|
||||
|
||||
Reference in new issue
Block a user