hyperledger-web3j / web3j-maven-plugin

web3j Maven plugin
Apache License 2.0
117 stars 83 forks source link

Path for ABI & BIN is wrong #106

Closed hendrikebbers closed 1 year ago

hendrikebbers commented 1 year ago

When creating ABI and BIN artifacts the path is based on the defined outputDirectory and the packageName. See JavaClassGeneratorMojo#createPath(String destinationPath):

private Path createPath(String destinationPath) throws IOException {
    Path path = Paths.get(destinationPath, packageName);

    if (!path.toFile().exists()) {
        Files.createDirectories(path);
    }
    return path;
}

Since the packageName is using . as a separator the created path is always horrible.

Concrete sample:

In the pom the following config for the plugin has been defined:

<configuration>
  <soliditySourceFiles>...</soliditySourceFiles>
  <outputFormat>java,abi,bin</outputFormat>
  <outputDirectory>
    <java>${project.basedir}/target/generated-sources/java</java>
    <bin>${project.basedir}/target/generated-sources/bin</bin>
    <abi>${project.basedir}/target/generated-sources/abi</abi>
  </outputDirectory>
  <packageName>org.sample.generated</packageName>
</configuration>

In that case all Java classes will be generated in the folder target/generated-sources/java/org/sample/generated/ but all BIN files will be generated in the folder target/generated-sources/java/org.sample.generated/. As you can see org/sample/generated/ is not the used folder structure here but a single org.sample.generated/ folder has been created. It's the same for the ABI files.

Possible solution: Just replace . in the createPath method by /.

hendrikebbers commented 1 year ago

Fixed