如何停止 Apache maven覆盖文件夹
我有以下目录层次结构:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看该插件的代码,您会发现该代码已被硬编码以清理目录:
https://github.com/dtrott/maven-protoc-plugin/blob/master/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java#L154
有解决这个问题的两种方法..要么将输出目录设置为临时目录,然后使用 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
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
我已经通过以下方法解决了我的问题:
但是,我收到此错误“发生了 Ant BuildException:只能设置 tofile 和 todir 之一”
I have solved my issue by the following :
However , I get this error "An Ant BuildException has occured: Only one of tofile and todir may be set"