gradle-maven-publish-auth icon indicating copy to clipboard operation
gradle-maven-publish-auth copied to clipboard

Properties in server id attribute not expanded

Open ssams opened this issue 2 years ago • 0 comments

When using properties in the server id attribute within the settings.xml, credentials are not setup correctly as the properties are not expanded (expansion only happens for username / password attributes).

For example, using the plugin with the following settings.xml does not work:

<?xml version="1.0"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <servers>
    <server>
      <id>${env.MAVEN_REPO_ID}-snapshots</id>
      <username>user-snapshots</username>
      <password>***</password>
    </server>
    <server>
      <id>${env.MAVEN_REPO_ID}-releases</id>
      <username>user-releases</username>
      <password>***</password>
    </server>
  </servers>
</settings>

The plugin does not expand the id attributes and add credentials for the literal values, from the logs:

2021-08-03T06:54:23.230+0000 [DEBUG] [org.hibernate.build.publish.auth.maven.SettingsXmlCredentialsProvider] Adding credentials for server : ${env.MAVEN_REPO_ID}-snapshots
2021-08-03T06:54:23.268+0000 [DEBUG] [org.hibernate.build.publish.auth.maven.SettingsXmlCredentialsProvider] Adding credentials for server : ${env.MAVEN_REPO_ID}-releases

The repository id therefore does not match the repository name setup in the gradle build, thus gradle is not able to find matching credentials and proceeds without them, trying to run an unauthenticated upload which fails.

(note: example originally used in a CI context, hence the need to set the repo ID from the environment)

Expected behavior would be expansion of properties also in the id attribute, e.g. when the environment variable MAVEN_REPO_ID=foo is set credentials should be added for repositories foo-snapshots and foo-releases in the above example

ssams avatar Aug 03 '21 07:08 ssams