How to copy unversioned test resources during rele

2019-03-04 02:24发布

问题:

My Question is very similar to "Maven doesn't copy untracked resources while releasing". I have test resources which are not under version control. As testing is part of release:perform that fails without those resources.

How can I tell Maven to copy those unversioned test resources into target/checkout/target/test-classes/. I really would prefer not to skip testing. Those test resource won't come into the public vcs as they have credentials for a webservice.

回答1:

There seems to be many ways to achieve this. One way is with the maven-resources-plugin and a profile. The release-plugin sets during release:perform the profile release-plugin. You simply have add the maven-resources-plugin into that profile (or a custom profile which is activated by <releaseProfiles>).

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                <resources>
                    <resource>
                        <directory>${basedir}/../../src/test/resources/</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

With org.sonatype.oss:oss-parent it's a bit different, as that parent disables <useReleaseProfile> but uses sonatype-oss-release.



回答2:

Just as a quick reply :

You SHOULD not include unversionned resources. This is not Maven philisophy ... indeed you MUST not :).

maven and maven-release-plugin aimed to provide repeatable build. You CANNOT ensure that your build will ever deliver the same result if you rely on unversioned, let say uncontroled, resources.

For later purposes, credentials can be encrypted easily :

  • https://maven.apache.org/guides/mini/guide-encryption.html
  • http://blog.sonatype.com/2009/10/maven-tips-and-tricks-encrypting-passwords/