如何停止 Apache maven覆盖文件夹

发布于 2024-12-11 13:28:45 字数 1118 浏览 0 评论 0原文

我有以下目录层次结构:

generated 

   |    
   | -->java

Java 目录有以下包:com.model

,其中包含我在编译应用程序之前从某处复制/粘贴的 java 模型。

我使用 Protocol buffer 的问题是,我告诉 maven 将生成的文件输出到相同的先前目录中,但通过新包:

结果:Protocol buffer 生成新包并删除旧包。
我不知道为什么它会这样做,尽管包名称不同?

这是我用来从协议缓冲区生成 java 的 pom 部分:

        <plugin>
            <groupId>com.google.protobuf.tools</groupId>
            <artifactId>maven-protoc-plugin</artifactId>
            <configuration>
                <protocExecutable>C:\protoc.exe</protocExecutable>
                <protoSourceRoot>./src/proto</protoSourceRoot>
                <outputDirectory>./src/generated/java</outputDirectory>

            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I have the following directory hierarchy:

generated 

   |    
   | -->java

Java directory has the following package: com.model

that contains java models that I copy/paste from somewhere before I compile the application.

The issue that I use Protocol buffer and I tell maven to output the generated files on same previous directory BUT over a new package:

Result : Protocol buffer generates the new package and deletes the old package.
I have no idea why does it do that although the package names are different?

Here is that part of pom I use to generate java from protocol buffer:

        <plugin>
            <groupId>com.google.protobuf.tools</groupId>
            <artifactId>maven-protoc-plugin</artifactId>
            <configuration>
                <protocExecutable>C:\protoc.exe</protocExecutable>
                <protoSourceRoot>./src/proto</protoSourceRoot>
                <outputDirectory>./src/generated/java</outputDirectory>

            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眸 2024-12-18 13:28:45

如果您查看该插件的代码,您会发现该代码已被硬编码以清理目录:

https://github.com/dtrott/maven-protoc-plugin/blob/master/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java#L154

// Quick fix to fix issues with two mvn installs in a row (ie no clean)
cleanDirectory(outputDirectory);

有解决这个问题的两种方法..要么将输出目录设置为临时目录,然后使用 Maven 复制插件或 Maven 构建插件将文件复制到您选择的目录中,或者修改 Maven 插件以删除该行(或者更好的是使其可配置)。

汤米

if you look at the code for the plugin you'll see that the code has been hardcoded to clean the directory:

https://github.com/dtrott/maven-protoc-plugin/blob/master/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java#L154

// Quick fix to fix issues with two mvn installs in a row (ie no clean)
cleanDirectory(outputDirectory);

There's 2 ways to solve this..either set the output directory to a temp directory and then use the maven copy plugin or the maven build plugin to copy the files into the directory of your choice, or modify the maven plugin to remove that line (or better yet make it configurable).

Tommy

末蓝 2024-12-18 13:28:45

我已经通过以下方法解决了我的问题:

<plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
                  <execution>
                      <phase>generate-resources</phase>
                      <goals>
                          <goal>run</goal>
                      </goals>
                      <configuration>
                          <tasks>
                              <delete dir="./destination"/>
                              <copy todir="./destination">
                                    <fileset dir="./source"/>
                              </copy>
                              <delete dir="./source"/>
                          </tasks>
                      </configuration>
                  </execution>
              </executions>
        </plugin>

但是,我收到此错误“发生了 Ant BuildException:只能设置 tofile 和 todir 之一”

I have solved my issue by the following :

<plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
                  <execution>
                      <phase>generate-resources</phase>
                      <goals>
                          <goal>run</goal>
                      </goals>
                      <configuration>
                          <tasks>
                              <delete dir="./destination"/>
                              <copy todir="./destination">
                                    <fileset dir="./source"/>
                              </copy>
                              <delete dir="./source"/>
                          </tasks>
                      </configuration>
                  </execution>
              </executions>
        </plugin>

However , I get this error "An Ant BuildException has occured: Only one of tofile and todir may be set"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文