1

I need to deploy my project into artifactory. For this purpose I use maven-assembly-plugin together with artifactory-maven-plugin

only I can use for building of mvn is this CMD (small updates are possible):

mvn -e -B -U clean deploy -DskipIntegrationTests=false -DskipCoverageReport=false  -Dservice_name=sample_service

What I can not do in mvn command is update service name. It will be always "sample_service" or some other constant which represent name of service

Because I do not know name of service (there could be more services) my base part of pom.xml looks like this (artifactId is created dynamically from property service_name):

    <groupId>my.group.id</groupId>
    <artifactId>${service_name}</artifactId>
    <version>2.0.0-SNAPSHOT</version>

The problem is that parameter -Dservice_name will always consists "underscores". Because of conventions artifact has to consists "dashes" instead of "underscores".

Is there any way (some plugin for instance) how I can do something like this?

    <groupId>my.group.id</groupId>
    <artifactId>${service_name}.replaceAll("_","-")</artifactId>
    <version>2.0.0-SNAPSHOT</version>

In short for property service_name I need replace underscores by dashes before building of artifact.

Thanks for answers.

Juraj
  • 738
  • 2
  • 9
  • 26

3 Answers3

0

This cannot be done.

Properties used inside <artifactId> can only be set through the command line. You have no chance to manipulate them in Maven. The only chance I see is to change the command line, so that you do the replacement before you send the parameter to Maven.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

I found a solution for my problem. But I am not sure if it is correct way how to solve it. I used plugin gmaven-plugin

        <plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>pre-clean</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                project.getModel().setArtifactId(project.properties["service_name"].replaceAll('_', '-'))
                                project.getArtifact().setArtifactId(project.properties["service_name"].replaceAll('_', '-'))
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

After that I use maven-assembly plugin which upload data into artifactory. And this plugin read artifact id from instance "project.getArtifacts()" so I update it directly. So I updated artifact id directly in maven instance. As I say it is not 100 percent correct but in my case it helps

Juraj
  • 738
  • 2
  • 9
  • 26
-2

You can do this with the buildhelper plugin, it has a goal regex-property which can set a property based on an initial value (your service_name property) and a regular expression to replace with a replacement value.

Example from the usage page (adapted because the value used made no sense):

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>regex-property</id>
            <goals>
              <goal>regex-property</goal>
            </goals>
            <configuration>
              <name>human.version</name>
              <value>${project.version}</value>
              <regex>-SNAPSHOT</regex>
              <replacement> pre-release development version</replacement>
              <failIfNoMatch>false</failIfNoMatch>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
kutschkem
  • 7,826
  • 3
  • 21
  • 56
  • It does not work. I used the following config but it did not affect the artifact_id itself: artifact_id ${artifact_id} _ - true – Juraj Jun 24 '19 at 11:59
  • Following https://stackoverflow.com/a/14727072/927493, properties for the artifactId can only be set from the command line. Parameters from the pom itself or from Maven plugins cannot be used. – J Fabian Meier Jun 24 '19 at 12:07