Canvas addon with VAADIN 8, Gradle and SpringBoot - java

I am new to all Gradle, VAADIN and Spring, and am just working through a simple VAADIN Spring Boot tutorial (https://spring.io/guides/gs/crud-with-vaadin/) and tried to add the Canvas add-on from https://github.com/hezamu/vaadincanvas, but when I add the compile dependency
compile("org.vaadin.hezamu:canvas:2.3.0")
a VAADIN widget compile will fail with tons of weird errors:
Using Gradle Vaadin Plugin 1.3.1
:vaadinPluginVersionCheck SKIPPED
:compileJava UP-TO-DATE
:vaadinUpdateWidgetset
:processResources UP-TO-DATE
:classes UP-TO-DATE
:vaadinClassPathJar UP-TO-DATE
Errors in 'jar:file:/C:/Users/msc/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-client/8.1.8/93548adad170aea9fe62ab742908fe63fe0ec321/vaadin-client-8.1.8.jar!/com/vaadin/client/extensions/DragSourceExtensionConnector.java'
Line 413: The method getState() from the type DragSourceExtensionConnector refers to the missing type DragSourceState
Line 38: The import com.vaadin.shared.ui.dnd cannot be resolved
Line 433: DragSourceRpc cannot be resolved to a type
Line 605: DragSourceState cannot be resolved to a type
Line 39: The import com.vaadin.shared.ui.dnd cannot be resolved
Line 507: DragSourceRpc cannot be resolved to a type
Line 190: The method getState() from the type DragSourceExtensionConnector refers to the missing type DragSourceState
Line 433: The method getRpcProxy(Class<T>) in the type AbstractConnector is not applicable for the arguments (Class<DragSourceRpc>)
Line 212: DragSourceState cannot be resolved to a variable
Line 492: DropEffect cannot be resolved
Line 606: DragSourceState cannot be resolved to a type
Just by removing that one dependency, the project builds. This is the entire Gradle build file:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
classpath "com.devsoap.plugin:gradle-vaadin-plugin:1.3.1"
classpath "javax.validation:validation-api:1.1.0.Final"
}
}
plugins {
id "com.devsoap.plugin.vaadin" version "1.3.1"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.devsoap.plugin.vaadin'
jar {
baseName = 'gs-crud-with-vaadin'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/vaadin-snapshots" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url "http://oss.sonatype.org/content/repositories/vaadin-snapshots/" }
maven { url "http://vaadin.com/nexus/content/repositories/vaadin-addons/" }
maven { url "https://plugins.gradle.org/m2/" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencyManagement {
imports {
mavenBom 'com.vaadin:vaadin-bom:8.0.0'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.vaadin:vaadin-spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.vaadin.hezamu:canvas:2.3.0")
compile("com.h2database:h2")
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
What am I doing wrong? I am using Gradle 4.1 and Java 8.

There is a problem with your vaadin version. You have a bom with 8.0.0 but I guess the gradle plugin tries to use a newer version (8.1.8).
With Vaadin 8.1 the drag&drop Handling changed. I guess the addon doesn't support Vaadin 8.1 because it was released before.
You have three options.
Use some other addon if possible.
Fix the addon yourself
Or as a last resort add the following code to your build gradle to stay at Vaadin 8.0
vaadin {
version '8.0.7'
}

Well, I got it to work after "fine-tuning" all versions. VAADIN, its' addons and Gradle seem to be a fickle team. It works with the spring-boot gradle plugin 1.4.7.RELEASE (important!), VAADIN 8.1.1, the devsoap VAADIN Gradle plugin 1.3.1, the multifileupload addon 3.0.1 and the canvas addon 2.2.0.
Pretty much any change in any of these versions, and something falls apart.

Related

Gradle Upgrade issue: java.lang.IllegalArgumentException: Version must not be null o empty

we are facing issue while upgrading gradle 5.6 to gradle 7.2.
we have simple spring boot project(sub1) with one internal spring library project(sub 2). while sub2 is gradle spring lib which depends on sub1. Both projects are using same gradle and spring boot version.
Also we are trying to upgrade spring cloud to latest version which requires gradle upgrade and spring boot upgade. current version is shown below
gradle - 7.2
spring - 2.5.2
swagger - 2.9.2
Getting below error while I try hitting swagger url.
java.lang.IllegalArgumentException: Version must not be null o empty
Spring boot banner is blank and not showing version. we are suspecting this could be the issue.
Swagger home page shows below error:
Failed to load API definition
Gradle file:
repositories {
jcenter()
}
dependencies {
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4+'
}
}
plugins {
id "org.sonarqube" version "2.8"
id "com.gorylenko.gradle-git-properties" version "2.2.2"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: "jacoco"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
implementation.canBeResolved = true
}
jar {
archiveVersion = "${project.findProperty('APP_VERSION') ?: 'MANUAL_BUILD'}"
dependsOn configurations.runtimeClasspath
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
(configurations.runtimeClasspath-configuration.implementation).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
dependencies {
implementation('org.springframework:spring-webmvc:5.3.8')
implementation('org.apache.tomcat.embed:tomcat-embed-core:9.0.33')
implementation('org.aspectj:aspectjrt:1.9.5')
}
Please help us understand this issue.
there are some new features added as well as some features from gradle5X removed so, please go through the documentation once again and try to add the below dependencies that may help you in your API.
dependencies {
// Ensure you use the Groovy 3.x variant
testImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
testImplementation('org.junit.jupiter:junit-jupiter-api')
}
// Spock 2 is based on JUnit Platform and needs to be enabled explicitly.
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
also, go through this once to get more in detailed https://docs.gradle.org/current/userguide/upgrading_version_6.html

gradle Failed to apply plugin [id 'org.springframework.boot']

I am trying to run spring-boot project. I have some problem with gradle.
gradle build works fine, but I cannot run gradlew
Cannot run command:
./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
Here is error:
Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9
My gradle version 6.0
My gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.postgresql:postgresql')
testCompile("org.springframework.boot:spring-boot-starter-test")
}
gradle build works fine, there is no error.
The whole point of the Gradle wrapper is to have a fixed version of Gradle used in a project. This ensures that you don't by accident use an incompatible version than what the project supports. Another benefit is that it automatically downloads the correct version if you don't have it already.
When you type gradle (without the 'w'), you are invoking a manually downloaded distribution that you put on your path. This skips the wrapper part completely. In your case, you have apparently downloaded version 6 and updated the project to work with that version.
However, you have not updated the wrapper scripts, which is what you should have done instead. If you look in gradle/wrapper/gradle-wrapper.properties, you should see that it is set to 4.9, which is no longer compatible with your project.
To update it, you need to run the following command twice:
gradlew wrapper --gradle-version 6.1.1 --distribution-type all (assuming you want version 6.1.1, which is the latest at the time of this writing.)
The first time you run it, it will basically just change the version in gradle-wrapper.properties (e.g to 6.1.1). If this fails because the wrapper is too old compared to the project, just change the file manually with a text editor.
The second time you run it, Gradle will start up using that new version (e.g. 6.1.1) and, if needed, update the wrapper scripts themselves.
Also, if you like to start your Spring Boot application during development, just run gradlew bootRun. No need to build the jar and invoke java manually.
And also, instead of compile, use implementation in your dependencies. The former is deprecated (including testCompile).

How to set "-aspectpath" for the FreeFair AspectJ Gradle Plugin?

I am trying to use an AspectJ Annotation that is in a Library, that I am pulling into my project. My project uses Gradle, so I am attempting to use FreeFair AspectJ Gradle Plugin.
I need to be able to set the AspectJ -aspectpath argument, to the Library Dependency that Gradle is pulling in.
FreeFair, does not seem to have much Documentation, mainly just Sample Code.
In their sample code, I see that I can use this to set the -aspectpath to a local "project":
aspect project(":aspectj:aspect")
Does anyone know how to set the -aspectpath to an external library dependency?
I created an example Project and put it on GitHub: freefair-aspectpath-external-library.
Note: I am using io.freefair.gradle:aspectj-plugin version 2.9.5 because my project is stuck using Gradle version 4.10.3.
Update: I have created a bug for this: https://github.com/freefair/gradle-plugins/issues/46
Thanks to #larsgrefer, who provided the answer in the GitHub Issue (46).
For the io.freefair.aspectj.compile-time-weaving plugin 2.9.5 the configuration is named "aspects" instead of "aspect".
The following fixed the issue:
aspects project(":aspectj:aspect")
The full build file resembles:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
// 2.9.5 for use with Gradle 4.10.3.
classpath "io.freefair.gradle:aspectj-plugin:2.9.5"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "io.freefair.aspectj.compile-time-weaving"
aspectj.version = '1.9.3'
group 'xyz.swatt'
version '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
///// SWATT ///// https://mvnrepository.com/artifact/xyz.swatt/swatt
compile group: 'xyz.swatt', name: 'swatt', version: '1.12.0'
aspect "xyz.swatt:swatt:1.12.0"
}
aspect is a plain old gradle configuration.
This means you can use all the notations described here:
https://docs.gradle.org/current/userguide/dependency_types.html#dependency_types
https://docs.gradle.org/current/userguide/declaring_dependencies.html
dependencies {
aspect project(":my-aspect")
aspect "com.example.foo:bar-aspect:1.0.0"
aspect file("foo.jar")
}

Spring-Boot 2 fails in Gradle 4 build because of missing StyledTextOutputFactory, but why?

I'm trying to set up an OAuth2 authorization server based a tutorial by David Steiman. Currently, I want to check if that solution still works with most current versions of the included libraries. Working solely on the OAuth2ResourceServersub-project I change the corresponding entries in build.gradle so that it now looks like this:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE')
compile('org.springframework.security:spring-security-jwt:1.0.9.RELEASE')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Actually, at first, I tried Spring Boot version 1.5.10.RELEASE which works perfectly fine. But I need to use Spring 5 and therefore Spring Boot 2. But with 2.0.0.BUILD-SNAPSHOT, the spring boot Gradle plugin tells me that I have to use at least Gradle 4.0, so I can not use the Gradle wrapper that comes with the sample project. I had version 4.2.1 installed on my system but also tried with 4.5.1. What I get when using Gradle 4 is:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\stefa\Projekte\spring-cloud-oauth2-example\OAuth2ResourceServer\build.gradle' line: 16
* What went wrong:
A problem occurred evaluating project ':OAuth2ResourceServer'.
> Failed to apply plugin [class 'io.spring.gradle.dependencymanagement.DependencyManagementPlugin']
> Could not create task of type 'DependencyManagementReportTask'.
The root cause of the corresponding stack trace is:
...
Caused by: org.gradle.internal.service.UnknownServiceException: No service of type StyledTextOutputFactory available in ProjectScopeServices.
at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:324)
at org.gradle.api.internal.DependencyInjectingInstantiator.convertParameters(DependencyInjectingInstantiator.java:110)
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:79)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:119)
... 144 more
Which led me (among other places) there. The versions I am using should not have the problem anymore as far as I understand. But what completely confuses me is that I am actually using Spring Boot 2.0.0.BUILD-SNAPSHOT and Gradle 4.5.1 in my "real" project and it works perfectly well there.
I created an example-project which uses Spring-Boot 2 and Grade 4 and works perfectly well. What am I missing?

Plugin with id 'sonar' not found?

When trying to build my java project using Gradle I get the following issue:
plugin with id 'sonar' not found
at the following line in my build.gradle:
apply plugin: 'sonar'
This was previously working with Gradle version 1.7 and Java 7, however I have now updated to these newer versions:
gradle : 3.4.1
Java: 1.8
What could be causing this and how could I solve it?
The sonar plugin was renamed to 'org.sonarqube'.
To use this plugin you need to add a dependency:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
}
}
And then you can apply the plugin:
apply plugin: "org.sonarqube"
Also see the plugin page.

Categories