Skip to content

Profile-level properties from a settings.xml-activated profile are dropped before LRM init #12288

@ascheman

Description

@ascheman

Background

Apache Maven Resolver lets users configure the local repository manager
through aether.* properties. The Maven user manual describes
<properties> inside a <profile> as a regular way to set them, and
the documented activation channels for such a profile are:

  • CLI: mvn -P <id>
  • settings.xml: <activeProfiles><activeProfile>...</activeProfile></activeProfiles>
  • settings.xml: <profile><activation><activeByDefault>true</activeByDefault></activation>...

The first two channels propagate the profile's <properties> to the
resolver session as expected. The third does not.

Bug

When a profile is activated through
<activation><activeByDefault>true</activeByDefault></activation> in
settings.xml, the properties declared in that profile's
<properties> block never reach the
RepositorySystemSession.configProperties that the
EnhancedLocalRepositoryManager reads at initialization. Consequently,
aether.* settings declared in an active-by-default settings.xml
profile have no effect on the LRM — but the same <properties> block
on the same <profile> works correctly when the user activates it via
-P <id> on the CLI, or via <activeProfiles><activeProfile>... in the
same settings.xml.

This is observable to the user because
mvn help:evaluate -Dexpression=aether.enhancedLocalRepository.localPrefix
does report the configured value (the property is in the Maven session
elsewhere), yet the LRM behaves as if no aether.* configuration had
been set.

Reproducer

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example.aether</groupId>
  <artifactId>test-artifact</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
</project>

settings.xml (active-by-default — broken case):

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
  <profiles>
    <profile>
      <id>aether-split-via-settings</id>
      <activation><activeByDefault>true</activeByDefault></activation>
      <properties>
        <aether.enhancedLocalRepository.split>true</aether.enhancedLocalRepository.split>
        <aether.enhancedLocalRepository.localPrefix>mvb-foo</aether.enhancedLocalRepository.localPrefix>
      </properties>
    </profile>
  </profiles>
</settings>

For comparison, the same profile activated via <activeProfiles> (works correctly):

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
  <activeProfiles>
    <activeProfile>aether-split-via-settings</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>aether-split-via-settings</id>
      <properties>
        <aether.enhancedLocalRepository.split>true</aether.enhancedLocalRepository.split>
        <aether.enhancedLocalRepository.localPrefix>mvb-foo</aether.enhancedLocalRepository.localPrefix>
      </properties>
    </profile>
  </profiles>
</settings>

Run with each settings file:

mvn -s settings.xml -Dmaven.repo.local=$PWD/local-repo install
find local-repo -name 'test-artifact-1.0.pom'
settings.xml activation Found at
<activeProfiles><activeProfile>... (works) local-repo/mvb-foo/org/example/aether/test-artifact/1.0/test-artifact-1.0.pom
<activeByDefault>true</activeByDefault> (broken — actual) local-repo/org/example/aether/test-artifact/1.0/test-artifact-1.0.pom
<activeByDefault>true</activeByDefault> (expected) local-repo/mvb-foo/org/example/aether/test-artifact/1.0/test-artifact-1.0.pom

Versions

  • Maven 4.x master (sha 09fdd6a6, 4.1.0-SNAPSHOT)
  • Maven 3.9.16

Likely affects all versions on both lines; backport candidate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions