Web3j plugin for gradle task not found - java

I am beating against a wall for a whole week. I can't really see the reason why it doesn't work. I have a project where I want to run my Java project with the following build.gradle config:
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.3'
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id 'org.web3j' version "4.8.4"
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.suplab'
sourceSets {
main {
solidity {
srcDir "contracts"
}
}
test {
solidity {
srcDir "contracts"
}
}
}
ext {
web3jVersion = '4.8.4'
}
npmInstall {
enabled false
}
dependencies {
implementation "org.web3j:core:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate:hibernate-core:5.6.5.Final'
}
I use gradle version 6.8, since it was specified by developer of the plugin. When I try to build this project from the parent, root folder that is the root of the project, it fails with following error:
A problem occurred configuring project ':api'.
> Failed to notify project evaluation listener.
> Task with name 'resolveSolidity' not found in project ':api'.
> Could not create task ':api:generateTestContractWrappers'.
> Task with name 'compileTestSolidity' not found in project ':api'.
I can't figure it out. I checked it against the build that being generated with web3j-cli, and it's the same for the configuration property (both configs have it blank). So, I don't see any reason WHY it fails. Here's the webj3-cli generated build file:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id 'org.web3j' version '4.8.4'
}
group 'org.web3j'
version '0.1.0'
sourceCompatibility = 1.8
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
web3j {
generatedPackageName = 'org.web3j.generated.contracts'
excludedContracts = ['Mortal']
}
ext {
web3jVersion = '4.8.4'
logbackVersion = '1.2.3'
}
dependencies {
implementation "org.web3j:core:$web3jVersion",
"ch.qos.logback:logback-core:$logbackVersion",
"ch.qos.logback:logback-classic:$logbackVersion"
implementation "org.web3j:web3j-unit:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
jar {
manifest {
attributes(
'Main-Class': 'org.web3j.Web3App',
'Multi-Release':'true'
)
}
}
application {
mainClassName = 'org.web3j.Web3App'
}
test {
useJUnitPlatform()
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

Related

Eclipse libGDX project can't resolve gradle dependency of local repo but CLI has no problem?

I'm trying a libgdx project depending on a lib published in local repo with maven-publish:
// to publish locally:
// ~/gdx-gltf$ ./gradlew gltf:publishToMavenLocal
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'io.github.odys-z'
artifactId = 'gdx-gltf'
version = '0.1.0-SNAPSHOT'
from components.java
}
}
}
When I running the depending desktop with gradlew CLI, it's working:
./gradlew desktop:run
But in eclipse and right click the BasicTweenTest class (gradle project.ext.mainClassName) and run as java application, eclipse reported errors:
com.badlogic.gdx.utils.GdxRuntimeException: java.lang.Error: Unresolved compilation problems:
sceneAsset cannot be resolved to a variable
GLTFLoader cannot be resolved to a type
SceneModel cannot be resolved to a type
scenes cannot be resolved or is not a field
animationLoader cannot be resolved to a variable
The missing type is in the local repo dependency, gdx-gltf-0.1.0-SNAPSHOT. No matter what I cleaned projects or refreshed gradle, the error persisting appear.
Eclipse Screenshot with stacktrace report
desktop/build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/", "test/" ]
sourceSets.main.resources.srcDirs = ["../android/assets", "test"]
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.DesktopLauncher"
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.PlaneStarTest"
project.ext.mainClassName = "io.oz.wnw.norm.desktop.BasicTweenTest"
project.ext.assetsDir = new File("../android/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
The other two tests commented out above can run both in CLI and eclipse, which don't depend on the local published package. Any idea?
--------- parent project/build.gradle ----------
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
// jcenter()
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.9'
classpath 'com.android.tools.build:gradle:7.0.0-alpha08'
}
}
allprojects {
version = '1.0'
ext {
appName = "wn cloud"
gdxVersion = '1.9.14'
gltfVersion = '0.1.0-SNAPSHOT'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral()
// jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
}
}
project(":html") {
apply plugin: "java-library"
apply plugin: "gwt"
apply plugin: "war"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
api "com.badlogicgames.ashley:ashley:$ashleyVersion:sources"
}
}
project(":core") {
apply plugin: "java-library"
apply plugin: 'eclipse'
eclipse {
classpath {
downloadSources=true
downloadJavadoc = true
}
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
api 'io.github.odys-z:gdx-gltf:0.1.0-SNAPSHOT'
}
}
I faced the same problem. Turns out that LibGDX works with JDK 7 and any version compiled above won't work.
You need to enforce java to compile at version 1.7 before publishing locally
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Gradle multi-project repository configuration not working for spring-boot application

I have a simple multi-project structure as follows:
|- gps-framework
|- build.gradle
|- settings.gradle
|- gps-web-service
|----build.gradle
|----src/main....
Under the root build.gradle located in gps-framework/ looks like this:
plugins {
id 'java'
id "java-library"
id "maven-publish"
id "jacoco"
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
subprojects {
subproject ->
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
def isApp = subproject.name == 'gps-web-service'
if (isApp) {
apply plugin: 'java'
} else {
apply plugin: 'java-library'
}
group = 'com.mycompnay'
version = project.hasProperty('customVersion') ? project['customVersion'] : 'integration-SNAPSHOT'
//System.out.println(subproject.name)
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
}
compileTestJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
mavenLocal()
maven {
name "release"
url "my-custom-mvn-repo/release"
authentication {
//
}
}
maven {
name "snapshot"
url "my-custoom-mvn-repo/snapshot"
authentication {
//
}
}
}
configurations {
runtime.exclude(group: "org.slf4j", module:"slf4j-log4j12")
}
publishing {
repositories {
maven {
authentication {
//
}
def isSnapshot = subproject.version.contains('SNAPSHOT')
url = isSnapshot ? "my-custom-mvn-repo/snapshot" : "my-custom-mnv-repo/release"
}
}
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}
if (subproject.hasProperty('jacocoTestCoverageVerification')) {
subproject.check.dependsOn subproject.jacocoTestCoverageVerification
}
test {
testLogging {
exceptionFormat = 'full'
}
}
}
The build.gradle of sub-project gps-web-service located in gps-framework/gps-web-service looks like this:
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
From what I have read so far, since the repository settings are defined in the root build.gradle and these settings are injected into these subprojects, I do not need to redefine repository settings. This does not appear to be the case as when I run
./gradlew build
The error I get is:
Could not find org.springframework.boot:spring-boot-starter-web:.
Required by:
project :gps-web-service
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Am I misunderstanding the whole concept of injection of project properties or what am I missing here? I will try duplicating the repo settings in the sub-projects build.gradle but was hoping this is not necessary.
To solve this specific problem, I had to define the spring boot plugin in the sub-project's build.gradle as follows:
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
The resulting file looks like this:
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}

gradle generates protobuf class but shows compile error

The generated protobuf class is under generated-sources as expected.
But it has references to com.google.protobuf, for example below code. And I get compilation error saying com.google.protobuf not found.
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
The below is my build.gradle file.
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'com.google.protobuf' version '0.8.10'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
java {
// include self written and generated code
srcDirs 'src/main/java', 'generated-sources/main/java'
}
}
// remove the test configuration - at least in your example you don't have a special test proto file
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
generateProtoTasks.generatedFilesBaseDir = 'generated-sources'
generateProtoTasks {
// all() returns the collection of all protoc tasks
all().each { task ->
// Here you can configure the task
}
// In addition to all(), you may get the task collection by various
// criteria:
// (Java only) returns tasks for a sourceSet
ofSourceSet('main')
}
}
I think the problem is that the protobuf library is not showing up in the external libraries of my intellij project. Is there a way to make it work with gradle?
Working gradle file:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'com.google.protobuf' version '0.8.10'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.google.protobuf:protobuf-java:3.11.1'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
java {
// include self written and generated code
srcDirs 'src/main/java', 'generated-sources/main/java'
}
}
// remove the test configuration - at least in your example you don't have a special test proto file
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.6.0'
}
generateProtoTasks.generatedFilesBaseDir = 'generated-sources'
generateProtoTasks {
// all() returns the collection of all protoc tasks
all().each { task ->
// Here you can configure the task
}
// In addition to all(), you may get the task collection by various
// criteria:
// (Java only) returns tasks for a sourceSet
ofSourceSet('main')
}
}

Gradle tests not running with javafx project

build.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
mainClassName = 'mvc.Main'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.0-M1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.6.0-M1')
testCompile('org.mockito:mockito-core:3.1.0')
testCompile('com.athaydes.automaton:Automaton:1.3.2')
testCompile("org.testfx:testfx-core:4.0.16-alpha")
testCompile("org.testfx:testfx-junit:4.0.15-alpha")
testImplementation('org.hamcrest:hamcrest:2.2')
implementation 'com.github.cliftonlabs:json-simple:3.1.0'
}
applicationDefaultJvmArgs = [ "-Djdk.gtk.version=2"]
sourceCompatibility = 11
targetCompatibility = 11
test {
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
}
javafx {
modules = ['javafx.controls', 'javafx.fxml']
version = '11.0.2'
}
My project structure is the usual:
src/main/java/mvc/Main.java
src/test/java/mvc/MainTest.java
When I run gradle test or ./gradlew test tests it doesn't execute any tests, not sure what's wrong.
testCompile is no longer a suppored command, you should use testImplementation instead.

Spring Boot Can't find main class Multi module

I am having difficulties telling Spring the location of the Main class. So far I have only managed to correctly specify where it is when it is in pictures-service module (i.e., pictures-service/src/main/com.bachadiff.application/Application.java)
This is the file structure.
And this is the main gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
}
}
plugins {
id 'java'
id 'java-library'
id 'idea'
id "org.springframework.boot" version "2.0.2.RELEASE"
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
bootJar {
baseName = 'com.bachadiff.pictures-service'
version = '0.1.0'
mainClassName = 'com.bachadiff.application.Application'
}
version = '0.1.0'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext.common = [
spring_web : 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE',
spring_rest : 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE',
spring_mongo: 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE',
spring_test : 'org.springframework.boot:spring-boot-starter-test'
]
ext.test = [
junit: 'junit:junit:4.12'
]
dependencies {
api 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE'
api 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE'
api 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE'
compile project(':pictures-service-impl')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
The mainClassName should consist out of the package and the class name itself, so in your case that should be:
mainClassName = 'com.bachadiff.application.Application'
And since you are saying that you have a multi-project build, you should put this in the build.gradle for the pictures-service-application project

Categories

Resources