Does not run on "mvn compile"
4ntoine opened this issue · 7 comments
I have added plugin to generate wrapper for smart contract:
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>0.1.5-SNAPSHOT</version>
<configuration>
<packageName>name.antonsmirnov.apptogether.ethereum</packageName>
<sourceDestination>target/generated-sources/java</sourceDestination>
<nativeJavaType>true</nativeJavaType>
<soliditySourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
I'm running mvn generate-sources
in parent maven module using the plugin.
However i can't see any generating output:
------------------------------------------------------------------------
[INFO] Building ethereum 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ethereum ---
[INFO] Deleting /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (default) @ ethereum ---
[INFO] Source directory: /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target/generated-sources/java added.
[INFO]
[INFO] --- web3j-maven-plugin:0.1.5-SNAPSHOT:generate-sources (default) @ ethereum ---
[INFO]
[INFO] ------------------------------------------------------------------------
I can see output directory is not even created:
$ls /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target/generated-sources/java
ls: /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target/generated-sources/java: No such file or directory
I've tried to call $mvn web3j:generate-sources
in parent project too:
$mvn web3j:generate-sources
...
[ERROR] No plugin found for prefix 'web3j' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/asmirnov/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
Of coarse i have .sol file(s):
$ls ethereum/src/main/resources/
. .. AppetissimoContract.sol
I've found it works as expected if running mvn compile
on the module directly (in ./ethereum
directory), not on parent module. Did i miss anything?
PS. Parent module:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>name.antonsmirnov.apptogether</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
...
<module>ethereum</module>
...
</modules>
</project>
I think you should specify the plugin in the pluginManagement section of the multi-module root pom.
<modules>
...
<module>ethereum</module>
...
</modules>
<build>
<!-- In the multi-module root pom, use the pluginManagement to define the version of the maven-plugin -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>0.1.5-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
And in the specific module ethereum, clear the version of the plugin, since it is already defined in the multi-module root pom (the parent).
<parent>
<groupId>name.antonsmirnov.apptogether</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>../</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<!-- No version needed here, it is already defined in the multi-module root pom -->
<configuration>
<!-- This is where our specific configuration goes -->
</configuration>
</plugin>
</plugins>
</build>
I did what you've suggested - it still does not work. Neither mvn clean generate-sources
nor mvn clean web3j:generate-sources
on parent module:
$mvn clean generate-sources
...
------------------------------------------------------------------------
[INFO] Building ethereum 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ethereum ---
[INFO] Deleting /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (default) @ ethereum ---
[INFO] Source directory: /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target/generated-sources/java added.
[INFO]
[INFO] --- web3j-maven-plugin:0.1.5-SNAPSHOT:generate-sources (default) @ ethereum ---
[INFO]
[INFO] ------------------------------------------------------------------------
It works only if i run in the module:
./ethereum asmirnov$mvn clean generate-sources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ethereum 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ethereum ---
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (default) @ ethereum ---
[INFO] Source directory: /Users/asmirnov/Documents/dev/src/AppTogether/ethereum/target/generated-sources/java added.
[INFO]
[INFO] --- web3j-maven-plugin:0.1.5-SNAPSHOT:generate-sources (default) @ ethereum ---
[INFO] process 'AppetissimoContract.sol'
[INFO] Solidity Compiler found
[INFO] Built Class for contract 'AppetissimoContract'
[INFO] Built Class for contract 'SafeMath'
[INFO] ------------------------------------------------------------------------
To make it working and behaving like other code generating plugins (jaxws for example), I had to add the following:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<soliditySourceFiles>
<directory>${basedir}/src/main/solidity</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<sourceDestination>${basedir}/target/generated-sources/solidity</sourceDestination>
<packageName>my.package.name.here</packageName>
</configuration>
</execution>
</executions>
</plugin>
<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>${basedir}/target/generated-sources/solidity</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above should be the default behavior of the web3j-maven-plugin plugin I guess...
That's strange but it still does not work for me. The only thing that i've found is that you've added <id>...</id>
. Anything else?
Here is my pom.xml
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>0.1.5-SNAPSHOT</version>
<configuration>
<packageName>name.antonsmirnov.apptogether.ethereum</packageName>
<sourceDestination>target/generated-sources/java</sourceDestination>
<nativeJavaType>true</nativeJavaType>
<soliditySourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
You need the build-helper-maven-plugin configuration too, else maven-compiler-plugin won't pick up the generated Java sources.
Also, ${basedir} prefix is required within a multi-module project.