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

Can not use plugin with openzeppelin contract imports #52

Open
rstaq opened this issue Apr 8, 2020 · 11 comments
Open

Can not use plugin with openzeppelin contract imports #52

rstaq opened this issue Apr 8, 2020 · 11 comments

Comments

@rstaq
Copy link

rstaq commented Apr 8, 2020

I am not able to generate the Java Wrapper of my solidity token contract because of importing openzeppelin contracts into my contract.

<plugin>
    <groupId>org.web3j</groupId>
    <artifactId>web3j-maven-plugin</artifactId>
    <version>4.5.11</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate-sources</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <packageName>com.token.model</packageName>
        <sourceDestination>src/java/com/token/generated</sourceDestination>
        <nativeJavaType>true</nativeJavaType>
        <outputFormat>java</outputFormat>
        <soliditySourceFiles>
            <directory>src/main/resources/contracts</directory>
            <includes>
                <include>**/*.sol</include>
            </includes>
        </soliditySourceFiles>
        <outputDirectory>
            <java>src/java/com/token/generated</java>
        </outputDirectory>
    </configuration>
</plugin>

The installation and version of openzeppelin I use:
npm install [email protected]

The openzeppelin import in my contract file:
import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";

The error I get when executing the plugin:

C:/<path>/token/contracts/Token.sol:5:1: Error: Source "C:/<path>/token/node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol" not found: File outside of allowed directories.
import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";
@bakulinav
Copy link

@rw026 Hi! did you found solution for this issue? I have the same problem

@vanderheijden86
Copy link

Hi all, I have the same issue with the latest maven plugin. Any luck in solving it? @bakulinav @rw026 ?

@rstaq
Copy link
Author

rstaq commented Jun 2, 2021

@vanderheijden86 no luck. Just used the command line tool to generate my Java Files

@walshe
Copy link

walshe commented Oct 12, 2021

also have this issue. BTW can some one tell me if the webj3 maven plugin can just take abi files that I already generated from my truffle project and use these as input to create the Java proxies ? or must I compile the .sol files all over again with web3j ?

@walshe
Copy link

walshe commented Oct 12, 2021

i just got a little further by referencing openzepplin absolutely in my contracts:

pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

contract Items is ERC1155, Ownable {

    mapping(uint256 => bool) tokenIdMinted;
    
    constructor() ERC1155("http://localhost:8080/api/token-metadata/{id}") {
        
    }

    function mintCoupon(address owner, uint256 tokenId, uint256 amount)
        public onlyOwner
    {
        require(!tokenIdMinted[tokenId], "This token id was already minted");
        tokenIdMinted[tokenId] = true;
        _mint(owner, tokenId, amount, "");
        
    }
}

i got past the import errors but now I get this:

[INFO] --- web3j-maven-plugin:4.8.2:generate-sources (default-cli) @ seol ---
[INFO] Solidity: adding to process 'contracts/GameItem.sol'
[INFO] Solidity: adding to process 'contracts/Items.sol'
[INFO] Solidity: adding to process 'contracts/Migrations.sol'
[INFO] Solidity: adding to process 'contracts/GameItems.sol'
[INFO] Solidity: adding to process 'contracts/Box.sol'
[INFO] 	Compile Warning:
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /Users/Emmett/dev/walsingh/seol/blockchain/ethereum/learn/contracts/GameItems.sol

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /Users/Emmett/dev/walsingh/seol/blockchain/ethereum/learn/contracts/Items.sol

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.256 s
[INFO] Finished at: 2021-10-12T15:28:05+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.web3j:web3j-maven-plugin:4.8.2:generate-sources (default-cli) on project seol: A type incompatibility occurred while executing org.web3j:web3j-maven-plugin:4.8.2:generate-sources: class org.json.simple.JSONArray cannot be cast to class java.lang.String (org.json.simple.JSONArray is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @5533dc72; java.lang.String is in module java.base of loader 'bootstrap')
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.web3j:web3j-maven-plugin:4.8.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/Emmett/.m2/repository/org/web3j/web3j-maven-plugin/4.8.2/web3j-maven-plugin-4.8.2.jar
[ERROR] urls[1] = file:/Users/Emmett/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar
[ERROR] urls[2] = file:/Users/Emmett/.m2/repository/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar
[ERROR] urls[3] = file:/Users/Emmett/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.25/plexus-interpolation-1.25.jar
[ERROR] urls[4] = file:/Users/Emmett/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[5] = file:/Users/Emmett/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[6] = file:/Users/Emmett/.m2/repository/org/apache/maven/maven-builder-support/3.6.0/maven-builder-support-3.6.0.jar
[ERROR] urls[7] = file:/Users/Emmett/.m2/repository/org/apache/maven/resolver/maven-resolver-util/1.3.1/maven-resolver-util-1.3.1.jar
[ERROR] urls[8] = file:/Users/Emmett/.m2/repository/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar
[ERROR] urls[9] = file:/Users/Emmett/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar
[ERROR] urls[10] = file:/Users/Emmett/.m2/repository/org/eclipse/sisu/org.eclipse.sisu.inject/0.3.3/org.eclipse.sisu.inject-0.3.3.jar
[ERROR] urls[11] = file:/Users/Emmett/.m2/repository/com/google/inject/guice/4.2.1/guice-4.2.1-no_aop.jar
[ERROR] urls[12] = file:/Users/Emmett/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[ERROR] urls[13] = file:/Users/Emmett/.m2/repository/com/google/guava/guava/25.1-android/guava-25.1-android.jar
[ERROR] urls[14] = file:/Users/Emmett/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
[ERROR] urls[15] = file:/Users/Emmett/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar
[ERROR] urls[16] = file:/Users/Emmett/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar
[ERROR] urls[17] = file:/Users/Emmett/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar
[ERROR] urls[18] = file:/Users/Emmett/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar
[ERROR] urls[19] = file:/Users/Emmett/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.7.1/plexus-component-annotations-1.7.1.jar
[ERROR] urls[20] = file:/Users/Emmett/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar
[ERROR] urls[21] = file:/Users/Emmett/.m2/repository/org/apache/maven/shared/file-management/3.0.0/file-management-3.0.0.jar
[ERROR] urls[22] = file:/Users/Emmett/.m2/repository/org/apache/maven/shared/maven-shared-io/3.0.0/maven-shared-io-3.0.0.jar
[ERROR] urls[23] = file:/Users/Emmett/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[24] = file:/Users/Emmett/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[25] = file:/Users/Emmett/.m2/repository/org/web3j/codegen/4.8.4/codegen-4.8.4.jar
[ERROR] urls[26] = file:/Users/Emmett/.m2/repository/com/squareup/kotlinpoet/1.5.0/kotlinpoet-1.5.0.jar
[ERROR] urls[27] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.3.61/kotlin-reflect-1.3.61.jar
[ERROR] urls[28] = file:/Users/Emmett/.m2/repository/com/squareup/javapoet/1.7.0/javapoet-1.7.0.jar
[ERROR] urls[29] = file:/Users/Emmett/.m2/repository/info/picocli/picocli/3.0.0/picocli-3.0.0.jar
[ERROR] urls[30] = file:/Users/Emmett/.m2/repository/org/junit/platform/junit-platform-launcher/1.5.2/junit-platform-launcher-1.5.2.jar
[ERROR] urls[31] = file:/Users/Emmett/.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar
[ERROR] urls[32] = file:/Users/Emmett/.m2/repository/org/junit/platform/junit-platform-engine/1.5.2/junit-platform-engine-1.5.2.jar
[ERROR] urls[33] = file:/Users/Emmett/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar
[ERROR] urls[34] = file:/Users/Emmett/.m2/repository/org/junit/platform/junit-platform-commons/1.5.2/junit-platform-commons-1.5.2.jar
[ERROR] urls[35] = file:/Users/Emmett/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.5.2/junit-jupiter-engine-5.5.2.jar
[ERROR] urls[36] = file:/Users/Emmett/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.5.2/junit-jupiter-api-5.5.2.jar
[ERROR] urls[37] = file:/Users/Emmett/.m2/repository/org/junit/vintage/junit-vintage-engine/5.5.2/junit-vintage-engine-5.5.2.jar
[ERROR] urls[38] = file:/Users/Emmett/.m2/repository/org/web3j/core/4.8.4/core-4.8.4.jar
[ERROR] urls[39] = file:/Users/Emmett/.m2/repository/org/web3j/abi/4.8.4/abi-4.8.4.jar
[ERROR] urls[40] = file:/Users/Emmett/.m2/repository/org/web3j/utils/4.8.4/utils-4.8.4.jar
[ERROR] urls[41] = file:/Users/Emmett/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.65/bcprov-jdk15on-1.65.jar
[ERROR] urls[42] = file:/Users/Emmett/.m2/repository/org/web3j/crypto/4.8.4/crypto-4.8.4.jar
[ERROR] urls[43] = file:/Users/Emmett/.m2/repository/org/web3j/rlp/4.8.4/rlp-4.8.4.jar
[ERROR] urls[44] = file:/Users/Emmett/.m2/repository/org/web3j/tuples/4.8.4/tuples-4.8.4.jar
[ERROR] urls[45] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-unixsocket/0.21/jnr-unixsocket-0.21.jar
[ERROR] urls[46] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-ffi/2.1.9/jnr-ffi-2.1.9.jar
[ERROR] urls[47] = file:/Users/Emmett/.m2/repository/com/github/jnr/jffi/1.2.17/jffi-1.2.17.jar
[ERROR] urls[48] = file:/Users/Emmett/.m2/repository/com/github/jnr/jffi/1.2.16/jffi-1.2.16-native.jar
[ERROR] urls[49] = file:/Users/Emmett/.m2/repository/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar
[ERROR] urls[50] = file:/Users/Emmett/.m2/repository/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar
[ERROR] urls[51] = file:/Users/Emmett/.m2/repository/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.jar
[ERROR] urls[52] = file:/Users/Emmett/.m2/repository/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar
[ERROR] urls[53] = file:/Users/Emmett/.m2/repository/org/ow2/asm/asm-util/5.0.3/asm-util-5.0.3.jar
[ERROR] urls[54] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-a64asm/1.0.0/jnr-a64asm-1.0.0.jar
[ERROR] urls[55] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-x86asm/1.0.2/jnr-x86asm-1.0.2.jar
[ERROR] urls[56] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-constants/0.9.11/jnr-constants-0.9.11.jar
[ERROR] urls[57] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-enxio/0.19/jnr-enxio-0.19.jar
[ERROR] urls[58] = file:/Users/Emmett/.m2/repository/com/github/jnr/jnr-posix/3.0.47/jnr-posix-3.0.47.jar
[ERROR] urls[59] = file:/Users/Emmett/.m2/repository/com/squareup/okhttp3/okhttp/4.9.0/okhttp-4.9.0.jar
[ERROR] urls[60] = file:/Users/Emmett/.m2/repository/com/squareup/okio/okio/2.8.0/okio-2.8.0.jar
[ERROR] urls[61] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.4.10/kotlin-stdlib-1.4.10.jar
[ERROR] urls[62] = file:/Users/Emmett/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar
[ERROR] urls[63] = file:/Users/Emmett/.m2/repository/com/squareup/okhttp3/logging-interceptor/4.9.0/logging-interceptor-4.9.0.jar
[ERROR] urls[64] = file:/Users/Emmett/.m2/repository/io/reactivex/rxjava2/rxjava/2.2.2/rxjava-2.2.2.jar
[ERROR] urls[65] = file:/Users/Emmett/.m2/repository/org/reactivestreams/reactive-streams/1.0.2/reactive-streams-1.0.2.jar
[ERROR] urls[66] = file:/Users/Emmett/.m2/repository/org/java-websocket/Java-WebSocket/1.3.8/Java-WebSocket-1.3.8.jar
[ERROR] urls[67] = file:/Users/Emmett/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.10.0/jackson-databind-2.10.0.jar
[ERROR] urls[68] = file:/Users/Emmett/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.10.0/jackson-annotations-2.10.0.jar
[ERROR] urls[69] = file:/Users/Emmett/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0.jar
[ERROR] urls[70] = file:/Users/Emmett/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar
[ERROR] urls[71] = file:/Users/Emmett/.m2/repository/junit/junit/4.10/junit-4.10.jar
[ERROR] urls[72] = file:/Users/Emmett/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar
[ERROR] urls[73] = file:/Users/Emmett/.m2/repository/org/web3j/web3j-sokt/0.2.1/web3j-sokt-0.2.1.jar
[ERROR] urls[74] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.61/kotlin-stdlib-jdk8-1.3.61.jar
[ERROR] urls[75] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.3.61/kotlin-stdlib-jdk7-1.3.61.jar
[ERROR] urls[76] = file:/Users/Emmett/.m2/repository/com/github/zafarkhaja/java-semver/0.9.0/java-semver-0.9.0.jar
[ERROR] urls[77] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlinx/kotlinx-serialization-runtime/0.14.0/kotlinx-serialization-runtime-0.14.0.jar
[ERROR] urls[78] = file:/Users/Emmett/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.60/kotlin-stdlib-common-1.3.60.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Process finished with exit code 1

:(

@intothemoonlite
Copy link

@walshe did you get it fixed? I fixed it is by adding pathPrefixes:

<configuration>
                    ...
                    <pathPrefixes>
                        <pathPrefix>@openzeppelin=../contract-dependencies/node_modules/@openzeppelin</pathPrefix>
                    </pathPrefixes>
</configuration>

@walshe
Copy link

walshe commented Nov 1, 2021

oh nice I will try.. In the end I went the long long way around and created a separate web3j project with the cli command web3j new.., copied the sol files in there and then generated the wrappers in there.. I then copied the generated wrappers back into my project

@intothemoonlite
Copy link

@walshe thanks. still facing some other issues here and might have to resort to using that.

@marko-lazic
Copy link

@walshe did you get it fixed? I fixed it is by adding pathPrefixes:

<configuration>
                    ...
                    <pathPrefixes>
                        <pathPrefix>@openzeppelin=../contract-dependencies/node_modules/@openzeppelin</pathPrefix>
                    </pathPrefixes>
</configuration>

But when you specify path like that then it complains
Could not compile Solidity files
[ERROR] Error: Source "/home/marko/projekti/spring5/demo-chain/src/main/@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File outside of allowed directories.

@rstaq
Copy link
Author

rstaq commented Nov 19, 2021

Do you see your ERC721.sol file in your file explorer at path /home/marko/projekti/spring5/demo-chain/src/main/@openzeppelin/contracts/token/ERC721/ERC721.sol?

@VincentFantasy
Copy link

VincentFantasy commented Aug 31, 2023

maven-build-plugins

<plugin>
                <groupId>org.web3j</groupId>
                <artifactId>web3j-maven-plugin</artifactId>
                <version>4.10.0</version>
                <configuration>
                    <packageName>com.github.fantasy.web3j.contract</packageName>
                    <nativeJavaType>true</nativeJavaType>

                    <soliditySourceFiles>
                        <directory>src/main/solidity</directory>
                        <includes>
                            <include>contract/*.sol</include>
                        </includes>
                    </soliditySourceFiles>

                    <outputDirectory>
                        <java>src/main/java/</java>
                        <bin>src/main/bin</bin>
                        <abi>src/main/abi</abi>
                    </outputDirectory>

                   <pathPrefixes>
                            <pathPrefix>@openzeppelin=@openzeppelin</pathPrefix>
                    </pathPrefixes>
                </configuration>
            </plugin>

path
image

@OpenZeppelin
https://github.com/OpenZeppelin/openzeppelin-contracts download and rename @OpenZeppelin
or

npm install -g @openzeppelin/contracts

and go to your node_modules get it, windows like

C:/Users/your user name/AppData/Roaming/npm/node_modules/

your sol file

// SPDX-License-Identifier: MIT

pragma solidity > 0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Erc20T is ERC20 {

    constructor(uint _totalSuperNum) ERC20("T test","T") {
        _mint(msg.sender,_totalSuperNum);
    }

}

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

7 participants