Search code examples
javamavenpom.xml

POM xml with credentials for Custom Repo


Could you please provide assistance with the following POM XML? I am encountering the error message Could not transfer metadata io.smkfdk7.commons:commons-utils/maven-metadata.xml from/to custom-repo when running the mvn clean package goals. I am aware that using a settings.xml file is recommended for security purposes, but it is taking some time to set up in our Azure DevOps pipelines. Therefore, I would like to find a solution for resolving private artifacts by including login credentials in my POM XML at the moment. Essentially, I would like to know how to specify the login credentials for my custom repo in the POM XML. POM.XML

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.0.2</version>
      <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.vit-uk-life-dto.dmdex</groupId>
  <artifactId>dmdex-core-service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>DMDex</name>
  <description>DMDex application for Disruption management and Documentation</description>
  <repositories>
      <repository>
          <id>central</id>
          <url>https://repo.maven.apache.org/maven2/</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
              <enabled>false</enabled>
          </snapshots>
      </repository>
      <repository>
          <id>custom-repo</id>
          <url>https://vit-uk-life-dto.com/artifactory/appsmav-main-maven-local</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
              <enabled>false</enabled>
          </snapshots>
      </repository>
  </repositories>
  <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-validator</artifactId>
          <version>8.0.0.Final</version>
      </dependency>

      <dependency>
          <groupId>io.smkfdk7.commons</groupId>
          <artifactId>commons-io</artifactId>
          <version>1.3.0</version>
      </dependency>
      
      <dependency>
          <groupId>com.scapps.common.api</groupId>
          <artifactId>scapps-commons-api</artifactId>
          <version>1.0</version>
      </dependency>

      <dependency>
          <groupId>io.smkfdk7.commons</groupId>
          <artifactId>commons-utils</artifactId>
          <version>[1.0.0,2.0.0)</version>
      </dependency>

      <dependency>
          <groupId>io.smkfdk7.commons</groupId>
          <artifactId>commons-jwt</artifactId>
          <version>1.0.8</version>
      </dependency>

      <dependency>
          <groupId>org.glassfish.jersey.core</groupId>
          <artifactId>jersey-client</artifactId>
          <version>3.0.8</version>
      </dependency>
  </dependencies>

  <build>
      <finalName>dmdex-core-service</finalName>
      <plugins>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
              <configuration>
                  <excludes>
                      <exclude>
                          <groupId>org.projectlombok</groupId>
                          <artifactId>lombok</artifactId>
                      </exclude>
                  </excludes>
              </configuration>
          </plugin>
      </plugins>
  </build>

  <profiles>
      <profile>
          <id>custom-repo-auth</id>
          <activation>
              <activeByDefault>false</activeByDefault>
          </activation>
          <repositories>
              <repository>
                  <id>custom-repo</id>
                  <url>https://vit-uk-life-dto.com/artifactory/appsmav-main-maven-local</url>
                  <releases>
                      <enabled>true</enabled>
                  </releases>
                  <snapshots>
                      <enabled>false</enabled>
                  </snapshots>
              </repository>
          </repositories>
      </profile>
  </profiles>

  <properties>
      <java.version>17</java.version>
      <custom-repo-username>PID7552</custom-repo-username>
      <custom-repo-password>bvdbhsdvhfbvhfbvbfvhfhjfhfvbdfbvhfvh</custom-repo-password>
  </properties>

</project>

Solution

  • This is not possible. Credentials must be stored inside a settings.xml file.

    The Maven documentation specifically states this.