How "build" and deploy a plain text maven artifact
Asked Answered
Q

2

6

I have a maven module for holding a plain text file that I need to "build" (rename the file with name-version-classifier.extension format) and deploy on my maven repository. I know I can deploy it via command line but I want to know if i can write a pom.xml whereby I can achive the same result.

LDM.

Quaternion answered 17/10, 2013 at 13:46 Comment(0)
I
9

From the discussion How to attach a text file to a module's distribution? :

In the past i've made use of the Build Helper plug-in to attach additional artifacts https://www.mojohaus.org/build-helper-maven-plugin

The example of how to attach additional artifacts to your project shows how to attach a file; make your module of type pom and the additional artifact will be the only artifact deployed:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>some file</file>
              <type>extension of your file </type>
              <classifier>optional</classifier>
            </artifact>
            ...
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>
Iridescent answered 17/10, 2013 at 14:0 Comment(1)
<packaging>pom</packaging> is indeed important to add to the GAV of the pom.xmlLeola
M
1

Use build-helper-maven-plugin:attach-artifact

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <!-- add configuration for antrun or another plugin here -->
          </plugin>
          ...
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
              <execution>
                <id>attach-artifacts</id>
                <phase>package</phase>
                <goals>
                  <goal>attach-artifact</goal>
                </goals>
                <configuration>
                  <artifacts>
                    <artifact>
                      <file>some file</file>
                      <type>extension of your file </type>
                      <classifier>optional</classifier>
                    </artifact>
                    ...
                  </artifacts>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
Mcqueen answered 17/10, 2013 at 14:2 Comment(1)
in this way maven generate two artifact: a jar and the (desired) palaintext artifact, is possible to have only one (the second) artifact?Quaternion

© 2022 - 2024 — McMap. All rights reserved.