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.
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.
Related
I am trying to create a maven project. I added the dependencies as jar files and importing them in my class. But the class doesn't recognize it.
I tried a couple of options and serached but couldn't resolve. Please guide.
Attached below is the screenshot of my project str
Try this:
Right click your project and select maven then click update project. Select the project and select force update of snapshots/releases option. Then refresh the project and build it (if you do not see compilation error after updating).
Since the jar is not under web-inf folder you are seeing this error.
There are several ways to resolve this issue
add below profile
<profile>
<id>qa</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Dependencies directory created in target folder
mvn install dependency:copy-dependencies
I have main class which scan classpath and generates some files. I want maven to call this main method during maven package and place generated files in target directory. How to do that?
You can configure your pom.xml to run some method while executing package phase like this -
<build>
<plugins>
<plugin>
<groupId>some.group.id</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>some.package.where.your.main.Class</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After configuring pom.xml you may run the following command -
mvn package
Now the package phase of maven life cycle will execute the main() method from the class you have mentioned in <mainClass> </mainClass>.
See some other ways at: 3 ways to run Java main from Maven
I have the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Which works fine during packaging or installing:
mvn install or mvn package, however, as soon as I try to specify a TestNG Group to run for the tests:
mvn install -Dgroups=somegroup
it fails with the following error after tests finish running:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (javadoc-jar)
on project ibd.database.api: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar for parameter
#: Cannot find default setter in class org.apache.maven.plugin.javadoc.options.Group
Thanks for any info or guidance on this.
The problem is that both the surefire and javadoc plugins use the -Dgroups parameter, and in your case the javadoc plugin cannot find the "somegroup".
As far as I know there is no clean solution for this, but you can do a workaround by defining a custom property in your pom.xml:
<properties>
<surefire.groups></surefire.groups>
</properties>
Then use the property in the surefire configuration:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
...
<configuration>
<groups>${surefire.groups}</groups>
</configuration>
</plugin>
Now you can run the tests from command line using the surefire.groups property:
mvn install -Dsurefire.groups=somegroup
I have multi-module Maven project in which I run the maven-javadoc-plugin to generate javadoc. In my parent pom.xml I have defined the plugin build as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate-jar</goal>
</goals>
<phase>install</phase>
<configuration>
<!-- Specific configuration for the aggregate report -->
</configuration>
</execution>
</executions>
</plugin>
When I run mvn clean install the build fails with unresolved dependencies, but I see the following warning:
[WARNING] The dependency:
[my.application:my-module:jar:1.7.1] can't be resolved but
has been found in the reactor (probably snapshots). This dependency
has been excluded from the Javadoc classpath. You should rerun javadoc
after executing mvn install.
As I am currently building my-module 1.7.1, I would assume Maven to detect this and run the aggregate-jar after building my-module, but for some reason it expects my-module to already be installed in a repo.
My Maven version is 3.0.4. Please keep in mind that I am new to Maven builds so this may be a very simple question, but I was not able to find any answer.
Some observations:
The build succeeds if I first run mvn clean install without the javadoc plugin aggregate-jar goal
The javadoc plugin aggregate goal runs fine.
This bug refers exactly to my issue, but should have been solved in Maven 3 (2010)
I run this command in my parent pom and this is how I do it without issues:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I want to generate the docs, I do mvn javadoc:aggregate
I have a Multimodule project like this:
parent
entities
jibx-exporter
I have configured jibx in the pom of jibx-exporter like this:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<directory>src/main/resources</directory>
<includes>
<include>binding0.xml</include>
</includes>
<validate>true</validate>
<verbose>true</verbose>
<load>false</load>
<verify>false</verify>
<multimodule>true</multimodule>
<modules>
<module>com.dreipplus.profiler.server.api:profiler-server-api-vo</module>
</modules>
</configuration>
<executions>
<execution>
<goals>
<goal>bind</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
When i run mvn clean install on parent it works as expected.
But when i execute the application, the jibx bindings of entities are not in the installed jar.
How can i add this Generated files to the local maven repository (.m2)?
greeting Florian Huber
I think that the following command solves your problem.
mvn install:install-file -Dfile=xxx.jar -DgroupId=<group-id> -DartifactId=<artifact-id>
http://maven.apache.org/plugins/maven-install-plugin/usage.html
I have moved the binding into the Entititys Module, all generated Classes are now properly exported!