Skip to content

Commit

Permalink
[MNG-7914] Provide a single entry point for configuration (#1595)
Browse files Browse the repository at this point in the history
* [MNG-7914] Provide a single entry point for configuration
* [MNG-7914] Rename global -> installation
* [MNG-7914] Include time zone in Maven build timestamp
* [MNG-7914] Use a single place to document all maven properties
  • Loading branch information
gnodet authored Aug 22, 2024
1 parent 6668da3 commit 6ac914d
Show file tree
Hide file tree
Showing 40 changed files with 3,500 additions and 271 deletions.
1 change: 1 addition & 0 deletions apache-maven/src/assembly/maven/bin/m2.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
main is org.apache.maven.cli.MavenCli from plexus.core

set maven.conf default ${maven.home}/conf
set maven.installation.conf default ${maven.conf}

[plexus.core]
load ${maven.conf}/logging
Expand Down
40 changes: 40 additions & 0 deletions apache-maven/src/assembly/maven/conf/maven.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Maven user properties
#

maven.installation.conf = ${maven.home}/conf
maven.user.conf = ${user.home}/.m2
maven.project.conf = ${session.rootDirectory}/.mvn

# Comma-separated list of files to include.
# Each item may be enclosed in quotes to gracefully include spaces. Items are trimmed before being loaded.
# If the first character of an item is a question mark, the load will silently fail if the file does not exist.
${includes} = ?"${maven.user.conf}/maven.properties", \
?"${maven.project.conf}/maven.properties"

#
# Settings
#
# Define the default three levels for settings.
# The '-is' flag will override the 'maven.installation.settings' property.
# The '-ps' flag will override the 'maven.project.settings' property.
# The '-s' flag will override the 'maven.user.settings' property.
maven.installation.settings = ${maven.installation.conf}/settings.xml
maven.project.settings = ${maven.project.conf}/settings.xml
maven.user.settings = ${maven.user.conf}/settings.xml

#
# Toolchains
#
# Define the default three levels for toolchains.
# The '-it' flag will override the 'maven.installation.toolchains' property.
# The '-t' flag will override the 'maven.user.toolchains' property.
maven.installation.toolchains = ${maven.installation.conf}/toolchains.xml
maven.user.toolchains = ${maven.user.conf}/toolchains.xml

#
# Extensions
#
maven.installation.extensions = ${maven.installation.conf}/extensions.xml
maven.project.extensions = ${maven.project.conf}/extensions.xml
maven.user.extensions = ${maven.user.conf}/extensions.xml
7 changes: 4 additions & 3 deletions apache-maven/src/assembly/maven/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ under the License.
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| 2. Installation Level.
| This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
| ${maven.installation.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
| -is /path/to/installation/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
Expand Down
7 changes: 4 additions & 3 deletions apache-maven/src/assembly/maven/conf/toolchains.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ under the License.
|
| -t /path/to/user/toolchains.xml
|
| 2. Global Level. This toolchains.xml file provides configuration for all Maven
| 2. Installation Level.
| This toolchains.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/toolchains.xml.
| ${maven.installation.conf}/toolchains.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gt /path/to/global/toolchains.xml
| -it /path/to/installation/toolchains.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests that the global settings.xml shipped with the distribution is in good state.
* Tests that the installation settings.xml shipped with the distribution is in good state.
*
*/
class GlobalSettingsTest {
class InstallationSettingsTest {

@Test
void testValidGlobalSettings() throws Exception {
Expand Down
267 changes: 267 additions & 0 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.api;

import org.apache.maven.api.annotations.Config;

/**
* Configuration constants.
*/
public final class Constants {

/**
* Maven home.
*
* @since 3.0.0
*/
@Config(readOnly = true)
public static final String MAVEN_HOME = "maven.home";

/**
* Maven installation configuration directory.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.home}/conf")
public static final String MAVEN_INSTALLATION_CONF = "maven.installation.conf";

/**
* Maven user configuration directory.
*
* @since 4.0.0
*/
@Config(defaultValue = "${user.home}/.m2")
public static final String MAVEN_USER_CONF = "maven.user.conf";

/**
* Maven project configuration directory.
*
* @since 4.0.0
*/
@Config(defaultValue = "${session.rootDirectory}/.mvn")
public static final String MAVEN_PROJECT_CONF = "maven.project.conf";

/**
* Maven local repository.
*
* @since 3.0.0
*/
@Config(defaultValue = "${maven.user.conf}/repository")
public static final String MAVEN_REPO_LOCAL = "maven.repo.local";

/**
* Maven installation settings.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.installation.conf}/settings.xml")
public static final String MAVEN_INSTALLATION_SETTINGS = "maven.installation.settings";

/**
* Maven user settings.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.user.conf}/settings.xml")
public static final String MAVEN_USER_SETTINGS = "maven.user.settings";

/**
* Maven project settings.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.project.conf}/settings.xml")
public static final String MAVEN_PROJECT_SETTINGS = "maven.project.settings";

/**
* Maven installation extensions.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.installation.conf}/extensions.xml")
public static final String MAVEN_INSTALLATION_EXTENSIONS = "maven.installation.extensions";

/**
* Maven user extensions.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.user.conf}/extensions.xml")
public static final String MAVEN_USER_EXTENSIONS = "maven.user.extensions";

/**
* Maven project extensions.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.project.conf}/extensions.xml")
public static final String MAVEN_PROJECT_EXTENSIONS = "maven.project.extensions";

/**
* Maven installation toolchains.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.installation.conf}/toolchains.xml")
public static final String MAVEN_INSTALLATION_TOOLCHAINS = "maven.installation.toolchains";

/**
* Maven user toolchains.
*
* @since 4.0.0
*/
@Config(defaultValue = "${maven.user.home}/toolchains.xml")
public static final String MAVEN_USER_TOOLCHAINS = "maven.user.toolchains";

/**
* Extensions class path.
*/
@Config
public static final String MAVEN_EXT_CLASS_PATH = "maven.ext.class.path";

/**
* Maven output color mode.
* Allowed values are <code>auto</code>, <code>always</code>, <code>never</code>.
*
* @since 4.0.0
*/
@Config(defaultValue = "auto")
public static final String MAVEN_STYLE_COLOR_PROPERTY = "maven.style.color";

/**
* Build timestamp format.
*
* @since 3.0.0
*/
@Config(source = Config.Source.MODEL, defaultValue = "yyyy-MM-dd'T'HH:mm:ssXXX")
public static final String MAVEN_BUILD_TIMESTAMP_FORMAT = "maven.build.timestamp.format";

/**
* User controlled relocations.
* This property is a comma separated list of entries with the syntax <code>GAV&gt;GAV</code>.
* The first <code>GAV</code> can contain <code>*</code> for any elem (so <code>*:*:*</code> would mean ALL, something
* you don't want). The second <code>GAV</code> is either fully specified, or also can contain <code>*</code>,
* then it behaves as "ordinary relocation": the coordinate is preserved from relocated artifact.
* Finally, if right hand <code>GAV</code> is absent (line looks like <code>GAV&gt;</code>), the left hand matching
* <code>GAV</code> is banned fully (from resolving).
* <br/>
* Note: the <code>&gt;</code> means project level, while <code>&gt;&gt;</code> means global (whole session level,
* so even plugins will get relocated artifacts) relocation.
* <br/>
* For example,
* <pre>maven.relocations.entries = org.foo:*:*>, \\<br/> org.here:*:*>org.there:*:*, \\<br/> javax.inject:javax.inject:1>>jakarta.inject:jakarta.inject:1.0.5</pre>
* means: 3 entries, ban <code>org.foo group</code> (exactly, so <code>org.foo.bar</code> is allowed),
* relocate <code>org.here</code> to <code>org.there</code> and finally globally relocate (see <code>&gt;&gt;</code> above)
* <code>javax.inject:javax.inject:1</code> to <code>jakarta.inject:jakarta.inject:1.0.5</code>.
*
* @since 4.0.0
*/
@Config
public static final String MAVEN_RELOCATIONS_ENTRIES = "maven.relocations.entries";

/**
* User property for version filters expression, a semicolon separated list of filters to apply. By default, no version
* filter is applied (like in Maven 3).
* <br/>
* Supported filters:
* <ul>
* <li>"h" or "h(num)" - highest version or top list of highest ones filter</li>
* <li>"l" or "l(num)" - lowest version or bottom list of lowest ones filter</li>
* <li>"s" - contextual snapshot filter</li>
* <li>"e(G:A:V)" - predicate filter (leaves out G:A:V from range, if hit, V can be range)</li>
* </ul>
* Example filter expression: <code>"h(5);s;e(org.foo:bar:1)</code> will cause: ranges are filtered for "top 5" (instead
* full range), snapshots are banned if root project is not a snapshot, and if range for <code>org.foo:bar</code> is
* being processed, version 1 is omitted.
*
* @since 4.0.0
*/
@Config
public static final String MAVEN_VERSION_FILTERS = "maven.versionFilters";

/**
* User property for chained LRM: list of "tail" local repository paths (separated by comma), to be used with
* {@code org.eclipse.aether.util.repository.ChainedLocalRepositoryManager}.
* Default value: <code>null</code>, no chained LRM is used.
*
* @since 3.9.0
*/
@Config
public static final String MAVEN_REPO_LOCAL_TAIL = "maven.repo.local.tail";

/**
* User property for reverse dependency tree. If enabled, Maven will record ".tracking" directory into local
* repository with "reverse dependency tree", essentially explaining WHY given artifact is present in local
* repository.
* Default: <code>false</code>, will not record anything.
*
* @since 3.9.0
*/
@Config(defaultValue = "false")
public static final String MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE = "maven.repo.local.recordReverseTree";

/**
* User property for selecting dependency manager behaviour regarding transitive dependencies and dependency
* management entries in their POMs. Maven 3 targeted full backward compatibility with Maven2, hence it ignored
* dependency management entries in transitive dependency POMs. Maven 4 enables "transitivity" by default, hence
* unlike Maven2, obeys dependency management entries deep in dependency graph as well.
* <br/>
* Default: <code>"true"</code>.
*
* @since 4.0.0
*/
@Config(defaultValue = "true")
public static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY =
"maven.resolver.dependencyManagerTransitivity";

/**
* Resolver transport to use.
* Can be <code>default</code>, <code>wagon</code>, <code>apache</code>, <code>jdk</code> or <code>auto</code>.
*
* @since 4.0.0
*/
@Config(defaultValue = "default")
public static final String MAVEN_RESOLVER_TRANSPORT = "maven.resolver.transport";

/**
* Plugin validation level.
*
* @since 3.9.2
*/
@Config(defaultValue = "inline")
public static final String MAVEN_PLUGIN_VALIDATION = "maven.plugin.validation";

/**
* Plugin validation exclusions.
*
* @since 3.9.6
*/
@Config
public static final String MAVEN_PLUGIN_VALIDATION_EXCLUDES = "maven.plugin.validation.excludes";

/**
* ProjectBuilder parallelism.
*
* @since 4.0.0
*/
@Config(type = "java.lang.Integer", defaultValue = "cores/2 + 1")
public static final String MAVEN_PROJECT_BUILDER_PARALLELISM = "maven.projectBuilder.parallelism";

private Constants() {}
}
Loading

0 comments on commit 6ac914d

Please sign in to comment.