0

我在我的Java Maven 项目中使用git-crypt ( https://github.com/AGWA/git-crypt ) 来加密包含敏感数据(密码等)的属性文件。

准备发布运行没有问题。但是“mvn release:perform”的执行失败了,因为这个操作是自动化的:

  • 从 SCM 结帐发布标签
  • 构建和部署发布的代码

问题是,我的属性文件已加密签出,因此某些集成测试的执行失败。

在 release:perform 过程中应该可以以某种方式自动解密我的文件。

我需要这样的解决方案:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <phase>deploy</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>cmd</executable>
                <arguments>
                    <argument>/c</argument>
                    <argument>git-crypt unlock my-unlock-keyfile</argument>
                </arguments>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <completionGoals>exec:exec</completionGoals>
            </configuration>
        </plugin>
    </plugins>
</build>

但遗憾的是,此代码仅适用于准备发布。

4

1 回答 1

0

我现在找到了一个可行的解决方案:

<build>
    <plugins>   
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>cmd</executable>
                <arguments>
                    <argument>/c</argument>
                    <argument>git-crypt unlock path\to\my-unlock-keyfile</argument>
                </arguments>
                <successCodes>
                    <successCode>0</successCode>
                    <successCode>1</successCode> <!-- while release preparation exit code 1 it thrown because of unsaved changes; this is only a workaround; -->
                </successCodes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
        </plugin>
    </plugins>
</build>
于 2021-04-01T12:21:28.547 回答