Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem integrating web3j into maven clean install #100

Open
andras-ballai opened this issue Feb 6, 2023 · 1 comment
Open

Problem integrating web3j into maven clean install #100

andras-ballai opened this issue Feb 6, 2023 · 1 comment

Comments

@andras-ballai
Copy link

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.

@andras-ballai
Copy link
Author

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 still think that such a basic feature should either be added or its absence should be documented and solutions/workarounds to it mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant