Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.ether-camp:solcJ:v0.4.7'
}
dependencies {
implementation("com.github.ether-camp:solcJ:v0.4.7")
}
<dependency>
<groupId>com.github.ether-camp</groupId>
<artifactId>solcJ</artifactId>
<version>v0.4.7</version>
</dependency>
libraryDependencies += "com.github.ether-camp" % "solcJ" % "v0.4.7"
:dependencies [[com.github.ether-camp/solcJ "v0.4.7"]]
Solidity compiler binaries, packed into jar for use in Java based projects.
This project is not supported anymore. If you have any question or would like to contribute find us on Gitter.
Jars are available at: https://bintray.com/ethereum/maven/org.ethereum.solcJ-all/
Can be included in gradle via:
compile 'org.ethereum:solcJ-all:0.5.7'
We use jar in EthereumJ project, where we add addition layer of classes to interact with solc
:
https://github.com/ethereum/ethereumj/tree/develop/ethereumj-core/src/main/java/org/ethereum/solidity/compiler
And then we use code snippet for compilation:
String contractSrc =
"pragma solidity ^0.5.7;\n" +
"contract a {" +
" function() {throw;}" +
"}";
SolidityCompiler.Result res = SolidityCompiler.compile(
contractSrc.getBytes(), true, ABI, BIN, INTERFACE, METADATA);
System.out.println("Out: '" + res.output + "'");
System.out.println("Err: '" + res.errors + "'");
CompilationResult result = CompilationResult.parse(res.output);
CompilationResult.ContractMetadata a = result.contracts.get("a");
CallTransaction.Contract contract = new CallTransaction.Contract(a.abi);
System.out.printf(contract.functions[0].toString());