Maven Assembly Plugin - install the created assembly

前端 未结 3 703
执念已碎
执念已碎 2021-02-08 00:27

I have a project that simply consists of files. I want to package those files into a zip and store them in a maven repository. I have the assembly plugin configured to build t

相关标签:
3条回答
  • 2021-02-08 00:51

    I don't know wether this could be usefull for you, but as a JAR file is basically a ZIP file plus the META-INF information, you could create your project as a jar without sources and add the xip countents in src/main/resources without needing any plugin configuration.

    If you want your content to be in a different location, you can always do something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.myzip</groupId>
      <artifactId>myzip-artifact-id</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>jar</packaging>
      <build>
        <resources>
          <resource>
            <targetPath>.</targetPath>
            <filtering>false</filtering>
            <directory>${basedir}/zipcontent</directory>
            <includes>
              <include>**/*</include>
            </includes>
          </resource>
        </resources>
      </build>
    </project>
    

    I f you want your artifact to be installed and being accessible in a repository you will need to set it up for the deploy phase:

    http://maven.apache.org/plugins/maven-deploy-plugin/usage.html

    0 讨论(0)
  • 2021-02-08 00:52

    I have the assembly plugin configured to build the zip file and that part works just fine, but I cannot seem to figure out how to install the zip file?

    Well, the created assembly should get automatically attached to the project and then uploaded into the repository on an install and deploy goal. Can you show your pom?

    Update: With your current configuration, I don't think that the assembly gets created as part of your build. You need to bind the single goal to a lifecycle phase, typically package:

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          <descriptors>
            <descriptor>../packaging.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- append to the packaging phase. -->
            <goals>
              <goal>single</goal> <!-- goals == mojos -->
            </goals>
          </execution>
        </executions>
      </plugin>
    

    And now it should get installed/deployed properly.

    Also, if I want to use this assembly in another artifact, how would I do that? I am intending on calling dependency:unpack, but I don't have an artifact in the repository to unpack.

    You can declare a dependency on an assembly (using the right classifier and type in your case) but since dependency are resolved through the repository, you'll need to solve the first step first. Then, declare something like this (where the classifier is the assembly's id):

    <dependency>
      <groupId>com. ... .virtualHost</groupId>
      <artifactId>***</artifactId>
      <version>0.0.1</version>
      <classifier>...</classifier>
      <type>zip</type>
    </dependency>
    
    0 讨论(0)
  • 2021-02-08 01:02

    I think assemblies are supposed to be automatically attached to the build, but if that doesn't work, the Maven Build Helper "attach-artifact" goal attaches a specified file to be installed in the repository. I've used this plugin for installing files created by an external process like Ant or NSIS.

    0 讨论(0)
提交回复
热议问题