英文:
Problem integrating web3j into maven clean install
问题
我有一个多模块的Maven项目,我想从.sol文件中生成Java包装器,为了实现这个目标,我正在使用web3j的Maven插件。以下是相关的POM文件部分:
主 pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.9.4</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
子 pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
<configuration>
<soliditySourceFiles>
<directory>${project.basedir}/src/main/resources/solidity</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<packageName>org.example.project-name.wrappers</packageName>
<outputDirectory>
<java>${project.build.directory}/generated-sources/web3j/java</java>
</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
我使用以下命令使用Maven构建项目:call mvn clean -U install
。
文件确实生成,并且在正确的位置,但当Maven开始执行install的编译阶段时,会遇到以下错误:
Compilation failure
[ERROR] /C:/source/project/project-name/src/main/java/org/example/child/TestFile.java:[4,51]
package org.example.project-name.wrappers does not exist
TestFile
是一个尝试导入生成的文件之一。
我还有一个openapi
代码生成插件,它可以正确生成文件,导入这些文件时没有任何问题。
我没有找到web3j插件中可能遗漏的任何配置选项,也没有找到任何帮助mvn install
或mvn compile
考虑包装器生成目录的方法。
我尝试手动提取install命令的捆绑调用,并手动插入web3j:generate-sources:
call mvn clean
call mvn web3j:generate-sources
call mvn process-resources
call mvn compile
call mvn process-test-resources
call mvn test
call mvn package
call mvn install
call mvn deploy
但这也在编译阶段失败。我假设web3j插件不会更新存储所有生成源的变量,但这只是一个猜测,我不知道该如何修复这个问题。
英文:
I have a multi-module maven project where I want to generate java wrappers from .sol files, to achieve this I'm using web3j's maven plugin. Here are the (relevant sections of the) poms:
main pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.9.4</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
child pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
<configuration>
<soliditySourceFiles>
<directory>${project.basedir}/src/main/resources/solidity</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<packageName>org.example.project-name.wrappers</packageName>
<outputDirectory>
<java>${project.build.directory}/generated-sources/web3j/java</java>
</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
I'm build the project with maven with the following command: call mvn clean -U install
.
The files do generate, and in the correct location, but when maven begins the compile phase of install it runs into the following error:
Compilation failure
[ERROR] /C:/source/project/project-name/src/main/java/org/example/child/TestFile.java:[4,51]
package org.example.project-name.wrappers does not exist
TestFile
is an empty file that tries to import one of the generated files.
I also have an openapi
code generator plugin, it does generate files properly, and I run into no issues when importing those.
I didn't find any configuration options in the web3j plugin that I missed and I also didn't find any way to help mvn install
or mvn compile
consider the directory in which the wrappers are generated.
I tried manually extracting the bundled calls that install makes and manually interjecting the web3j:generate-sources:
call mvn clean
call mvn web3j:generate-sources
call mvn process-resources
call mvn compile
call mvn process-test-resources
call mvn test
call mvn package
call mvn install
call mvn deploy
But this too fails at compile. I'm assuming that the web3j plugin doesn't update a variable storing all generated sources, but that's just a guess and I don't know how I would fix that.
答案1
得分: 0
I managed to solve the issue using org.codehaus:build-helper-maven-plugin.
I added the plugin to the dependencies of my main pom and the relevant child (I use dependency management), then added the plugin to the child's pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/web3j</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I also figured out that my assumption was correct: web3j's plugin does not update the project's sources directory.
英文:
I managed to solve the issue using org.codehaus:build-helper-maven-plugin.
I added the plugin to the dependencies of my main pom and the relevant child (I use dependency management), then added the plugin to the child's pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/web3j</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I also figured out that my assumption was correct: web3j's plugin does not update the project's sources directory.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论