Switch a Gradle-based Vaadin 22 app to Vaadin 23 beta - gradle

I am a Gradle newbie, having used Maven in the past.
I successfully established a Vaadin 22.0.5 project using the Vaadin Latest - Gradle starter project downloaded from Hello World Starters page. The project successfully builds and runs using gretty > apprun in IntelliJ 2021.1 EAP Ultimate edition.
👉 How do I alter the project to use the current beta version of the next version, Vaadin 23.0.0.beta2, as listed on the Vaadin releases page?
First attempt
I changed the gradle.properties file which consists of this single line:
vaadinVersion=22.0.5
… to this:
vaadinVersion=23.0.0.beta2
I clicked the floating windoid, Load Gradle Changes.
I immediately see this error appear in the IDE’s Build pane:
Build file '/Users/my_user/IdeaProjects/GetJava/build.gradle' line: 11
Plugin [id: 'com.vaadin', version: '23.0.0.beta2'] was not found in any of the following sources:
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
Second attempt
After receiving Answer by cfrick, I did the following.
If found this at the top of the build.gradle file:
buildscript {
repositories {
maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
maven { url "https://plugins.gradle.org/m2/" }
}
}
So I made no edits there, as seemed to be accomplishing the same thing as the first part of the Answer.
I changed the entirety of the settings.gradle file from this:
pluginManagement {
plugins {
id 'com.vaadin' version "${vaadinVersion}"
}
}
… to this:
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = "https://maven.vaadin.com/vaadin-prereleases"
}
}
plugins {
id 'com.vaadin' version "${vaadinVersion}"
}
}
I changed the gradle.properties file which consists of this single line:
vaadinVersion=22.0.5
… to this, using beta1 rather than beta2 seen above.
vaadinVersion=23.0.0.beta1
After executing Tasks > build > clean, I get a BUILD SUCCESSFUL message.
But when I execute Gretty > apprun, I get the following error message.
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.vaadin:vaadin-bom:23.0.0.beta1.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/vaadin/vaadin-bom/23.0.0.beta1/vaadin-bom-23.0.0.beta1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
> Could not find com.vaadin:vaadin-core:.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Pre-release versions are released first in Vaadins own pre-release
repository. You would have to add the repository if you need access to
releases, that have not yet hit the public repos:
In build.gradle expand repositories by:
repositories {
// ...
maven {
url = "https://maven.vaadin.com/vaadin-prereleases"
}
}
In the settings.gradle add a repositories block too:
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = "https://maven.vaadin.com/vaadin-prereleases"
}
}
plugins {
id 'com.vaadin' version "${vaadinVersion}"
}
}

Related

Gradle: Invalid publication 'maven': artifact file does not exist

Java 11 and Gradle 7.2 here. I am trying to build a reusable library that I can (eventually) publish to a Maven repository and pull into other projects. But first I just want to get it publishing to my local m2 repo.
The project directory structure looks like:
mylib/
lib/
src/
build.gradle
Where build.gradle is:
plugins {
id 'java-library'
id 'maven-publish'
id 'io.freefair.lombok' version "6.5.0-rc1"
}
sourceCompatibility = 1.11
targetCompatibility = 1.11
archivesBaseName = 'mylib'
version = '1.0.0-RC1'
group = 'org.example'
repositories {
mavenCentral()
}
dependencies {
// omitted for brevity
)
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}
publishing {
publications {
maven(MavenPublication) {
artifact("build/libs/${archivesBaseName}-${version}.jar") {
extension 'jar'
}
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
publishToMavenLocal.configure {
mustRunAfter build
}
When I run gradle publishToMavenLocal I get:
% ./gradlew clean build publishToMavenLocal
> Task :lib:publishMavenPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
> Invalid publication 'maven': artifact file does not exist: '/Users/myuser/workspace/mylib/lib/build/libs/mylib-1.0.0-RC1.jar'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 833ms
6 actionable tasks: 6 executed
So it looks like even though I'm specifying (on the command line) to run clean then build then publishToMavenLocal, and even though I'm even specifying (in build.gradle) that publishToMavenLocal must run after build, it seems what is happening is:
publishToMavenLocal insists on running first (before clean or build)
Since the JAR hasn't been built yet, no JAR file exists at the location specified ("build/libs/${archivesBaseName}-${version}.jar")
The build fails because the artifact doesn't exist
So I think I just need to get build to run before publishToMavenLocal but I'm out of ideas.
You're mixing the plugins DSL (plugins { }) with legacy plugin application (apply plugin). That's not a big deal, but you should go with #sean's answer and use the plugins DSL instead which will solve your issue.
To your problem at hand
Could not get unknown property 'plugin'
That happens because you missed the : in apply plugin
apply plugin: 'maven-publish'
Try placing your plugins in this way. Not sure if that resolves your issue though.
plugins {
id 'java-library'
id 'maven-publish'
}

"Could not resolve all files for configuration" after upgrading Gradle

I have a Gradle script that downloads the latest snapshot artifact from a Nexus server. It's been working fine with Gradle 5.4 but doesn't seem to be willing to work after upgrading to Gradle 6.5.
These are the build.gradle contents:
apply plugin: "java"
repositories {
maven {
url "https://somerepo.com/repository/app-snapshot/"
credentials {
username 'a-user'
password 'a-password'
}
authentication {
basic(BasicAuthentication)
}
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
configurations {
component
}
dependencies {
component group: "com.bla.ble, name: "component-name", version: "${version}-SNAPSHOT"
}
task copyComponent(type: Copy) {
from configurations.component
into "/some/local/path"
}
Gradle fails as follows:
Execution failed for task ':copyWorkflow'.
> Could not resolve all files for configuration ':workflow'.
> Could not find com.bla.ble:component-name:3.2.0-SNAPSHOT.
Searched in the following locations:
- https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/maven-metadata.xml
- https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/component-name-3.2.0-20201130.163046-11.pom
Required by:
project :
I've I navigate to https://somerepo.com/repository/app-snapshot/com/bla/ble/component-name/3.2.0-SNAPSHOT/maven-metadata.xml this provides a valid metadata file and points to a snapshot that actually has a valid file.
I've then tried downgrading again to Gradle 5.4 and worked OK. I was also trying to find any deprecated options in Gradle 6.x but couldn't find what it makes it fail.
Found the solution through this post: https://discuss.gradle.org/t/how-to-fetch-maven-artifact-without-pom-file-in-gradle-6-0/33836/2
Short history: A breaking change introduced in Gradle 6.x prevents the artifacts from being downloaded if the POM is not present. To go around this requirement, the following needs to be added to the maven definition:
metadataSources {
artifact()
}
More info: https://docs.gradle.org/current/userguide/upgrading_version_5.html?_ga=2.181891495.1612153887.1606754101-263409462.1606754101#maven_or_ivy_repositories_are_no_longer_queried_for_artifacts_without_metadata_by_default

gradle can't download ua-parser file

I'm trying to test some jenkins job seed dsls and for that I needed to download in gradle all plugins jenkins had, one of them was blueocean and in my build.gradle I've got this line
testPlugins 'io.jenkins.blueocean:blueocean:1.23.2'
and I get thrown this exception
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find ua_parser:ua-parser:1.3.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- https://repo.maven.apache.org/maven2/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
- http://repo.jenkins-ci.org/releases/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- http://repo.jenkins-ci.org/releases/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
- https://jcenter.bintray.com/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- https://jcenter.bintray.com/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
Required by:
project : > io.jenkins.blueocean:blueocean:1.23.2 > io.jenkins.blueocean:blueocean-rest-impl:1.23.2
I tried running with gradlew 4.8.1 and 6.0.1
I tried addint the ua-parser to build.gradle
compile group: 'ua_parser', name: 'ua-parser', version: '1.3.0'
I tried removing all gradle cache and refresh dependencies
rm -rf ~/.gradle/cache
./gradlew test --refresh-dependencies # or ./gradlew build ..
I disabled the vpn so it wasn't some firewall not allowing me to connect to the site, maybe I have some outdated gradle repository stored ? (I'm not familiar with gradle yet, so maybe something simple is escaping my sight)
EDIT 1:
I think this might be related to missing repository so tried adding new one by hand I found the https://github.com/jenkinsci/blueocean-plugin and tried add it to settings.gradle
sourceControl {
gitRepository("https://github.com/jenkinsci/blueocean-plugin.git") {
producesModule("org.gradle.blueocean:utilities")
}
}
and then referencing in build.gradle
dependencies {
...
implementation 'org.gradle.blueocean:utilities'
but doesn't seem to work, does anyone know how to add/where to search for gradle repositories (specifically with blueocean poms)
had to add those lines in repositories in build.gradle
repositories {
mavenCentral()
maven { url 'http://repo.jenkins-ci.org/releases/' }
maven { url 'https://mvnrepository.com/artifact/io.jenkins.blueocean' }
maven { url 'https://mvnrepository.com/artifact/ua_parser/ua-parser' }
maven { url 'https://mvnrepository.com/artifact' }
maven { url 'https://maven.twttr.com/' }

How to check where gradle is downloading its dependencies from?

I have a project using gradle from building and due to some recent jcenter issues, we want to move all our dependencies to our artifactory. Now i have all the configuration ready and declared inside the gradle build files. I have also removed all traces of other maven repositories.
repositories {
maven {
url "${artifactory_contextUrl}/repo_name-generic"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
After doing a gradle clean build, i expected a lot of errors as i have never added those dependencies to our artifactory repo, but none came. The project builds fine and i can see them being downloaded.
My question now is, why is it working?
Is there a way i can check from which source the dependencies are coming from?
Also in artifactories GUI i cannot locate the packages inside the specified repo
Thanks!
If you ant to print the repositories a project is using, the following task will do it for you:
task printRepos {
doFirst {
project.repositories { repositories ->
repositories.forEach { repo ->
println("${repo.name}: ${repo.url}")
}
}
}
}
If you add it to your gradle build and invoke it gradle printRepos, you should get the repositories printed out
For more information regarding the API, check: https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/RepositoryHandler.html
https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
Also thanks to Bjorn for pointing out the doFirst/doLast problem.
rm -rf ~/.gradle/caches
./gradlew assembleDebug -i > ~/Desktop/dump
search dependency lib in dump file to check where it was downloaded from
For example, flexbox-2.0.1 was downloaded from jcenter:

Why am I getting "could not find com.android.tools.build:gradle" error?

This is based off my last question as well.
Following this tutorial, I cloned the project into my machine and am trying to get the project to build properly.
In the process of fixing the error I got in my last question, I encountered a new error.
This is the section of the build script I am trying to fix/edit
buildscript {
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' }
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.3'
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
Following the instructions on how to check Gradle version, I checked mine and saw that I was running Gradle version 2.2.1. Based off that, I changed
classpath 'com.android.tools.build:gradle:1.2.3'
to
classpath 'com.android.tools.build:gradle:2.2.1'
However after changing that build script code, and attempting to rebuild my project, I get the above mentioned error(full stack trace below)
Error:Could not find com.android.tools.build:gradle:2.2.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
file:/C:/Users/chris/.m2/repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
file:/C:/Users/chris/.m2/repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
Required by:
:theplanethatcouldntflygood:unspecified
Does anyone know why I am getting this error or how to fix this? It doesn't make sense for me to point the Java compiler(classpath) at a Gradle Version that I am not even using.
You are confusing between android gradle plugin and gradle version.
This classpath 'com.android.tools.build:gradle:1.2.3' is a gradle plugin for Android and as of this time, 1.2.3 is the latest.
The gradle version itself is in gradle-wrapper.properties file. 2.4 is the latest version,
Per #Hamidreza's answer, check the maven and jcenter repos. Indeed jcenter (currently) has newer tools than maven.
So in the top-level build.gradle file,
change "mavenCentral" to "jcenter" like this
repositories {
//mavenCentral()
jcenter()
}
you can find last version in this address :
repo1.maven.org/maven2/com/android/tools/build/gradle
jcenter.bintray.com/com/android/tools/build/gradle
buildscript {
repositories {
maven { url "https://jcenter.bintray.com" }
maven { url "http://repo1.maven.org/maven2" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://jcenter.bintray.com" }
maven { url "http://repo1.maven.org/maven2" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I fixed this exact issue by upgrading my version of Android Studio. I was receiving an error Could not find com.android.tools.build:gradle:2.2.0, and was running a 2.1.x version of Studio at the time.
A simple upgrade to 2.2.2 immediately fixed my issue. Hope this can help somebody!
If you're behind a proxy, make sure Android Studio is set up for that. It does NOT assume system proxy settings.
My copy of Studio + Gradle wasn't set up to go through the proxy, and as a result it was giving me this error. Would've been nice to get a clear "hey buddy, I can't hit the web", but I got this error instead.

Resources