Copying multiple resource directories to independent target directories with maven

前端 未结 9 1424
终归单人心
终归单人心 2020-12-05 04:03

The Maven resources plugin:

This goal requires that you configure the resources to be copied, and specify the outputDirectory.

C

相关标签:
9条回答
  • 2020-12-05 04:19

    This is the simpler solution I've found and it's working...

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <configuration>   
                </configuration>
            </plugin>
        </plugins> 
        <resources>
            <resource>
                <directory>${basedir}/src/main/java/org/mc2/mymusic/gui/main/Menu/resources</directory>
                <targetPath>${basedir}/target/classes/org/mc2/mymusic/gui/main/Menu/resources</targetPath>
                <filtering>false</filtering>
            </resource>
        </resources>  
    </build>
    

    Marco

    0 讨论(0)
  • 2020-12-05 04:20

    This is where the file ends up:

    <outputDirectory>${basedir}/target/blah</outputDirectory>
    

    This is where it is copied from:

    <directory>src/main/otherresources</directory>
    

    There would be an <include> or <includes> tag to tell the file name(s)

    Multiples

    You need multiple <execution>s with different <id>s for multiple folders:

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources-1</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/blah</outputDirectory>
              <resources>
                <resource>
                    <directory>blah</directory>
                    <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-resources-2</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/ughh</outputDirectory>
              <resources>
                <resource>
                    <directory>ughh</directory>
                    <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    
    0 讨论(0)
  • 2020-12-05 04:20

    Reading your example I don't think you have to include&configure the maven-resource-plugin. Just add those resource-elements to the <build><resources/>-tag. See http://maven.apache.org/ref/3.1.1/maven-model/maven.html#class_resource which other tags you can use.

    0 讨论(0)
  • 2020-12-05 04:21
        <resources>
            <resource>
                  <directory>${basedir}/src/scripts</directory>
                  <includes>
                      <include>data-octopus.ps1</include>
                  </includes>
                  <targetPath>${basedir}/target/data</targetPath>
            </resource>
            <resource>
                  <directory>${basedir}/src/scripts</directory>
                  <includes>
                      <include>service-octopus.ps1</include>
                  </includes>
                  <targetPath>${basedir}/target/service</targetPath>
            </resource>
        </resources>
    
        </plugins>
            ...
        </plugins>
    
    0 讨论(0)
  • 2020-12-05 04:32

    Maven hides everything to make it easier to code. There are several ways you can achieve this.

    1. Edit the default execution in Resources plugin. (Easiest) This also can be written using include tag or different resources
    2. Write different executions in Resources plugin.
    3. Use Antrun plugin. (You might as well write the whole build in ant)
    4. Maven Copy-rename plugin.
    5. And many other ways that I am not mentioning here....

    Edit the default plugin--

    <resources>
        <resource>
            <directory>${basedir}<directory>
            <includes>
                <include>blah</include>
                <include>ughh</include>
            </includes>
        <resource>
    <resources>
    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <outputDirectory>${basedir}/target</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
    
    0 讨论(0)
  • 2020-12-05 04:33

    For me this one works well in Maven 3:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>custom-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <resources>                                        
                                <resource>
                                    <targetPath>${basedir}/target/blah</targetPath>
                                    <directory>blah</directory>
                                    <filtering>true</filtering>
                                </resource>             
                                <resource>
                                    <targetPath>${basedir}/target/uggh</targetPath>
                                    <directory>uggh</directory>
                                    <filtering>false</filtering>
                                </resource>              
                            <encoding>UTF-8</encoding>
                        </configuration>            
                    </execution>
                </executions>
            </plugin>
    
    0 讨论(0)
提交回复
热议问题