Gradle properties in 2.6 vs 2.7 - gradle

If I specify in 'build.gradle' that belongs to the root:
allprojects {
version="1.0-SNAPSHOT"
}
Then I want to use the same version property in a subproject like that:
dependencies {
compile group: 'com.myproject.module', name: 'first', version: allprojects.version
}
In Gradle 2.6: it will put '[1.0-SNAPSHOT]'
In Gradle 2.7: it will be '1.0-SNAPSHOT' without brackets
What can be the reason for that? Is that due to some gradle issues in 2.6? In gradle 2.2.1 - it also works fine. Maybe you could recommend some best practices here?

answer can be found here (I posted the same question on gradle forum): https://discuss.gradle.org/t/gradle-properties-in-2-6-vs-2-7/11919

Related

Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:

I have just downloaded the springboot project from http://start.spring.io/. After running it I got this error.
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.4.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
* 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.
Can any one please suggest what is root cause.
I would recommend you to run gradle build command in your terminal.
After this, do a gradle sync.
Must be some problem with your IDE.
Hope this solves your issue.
Accepted answer didn't work for me. I am able to resolve this after adding settings.gradle file in project root with,
settings.gradle:
pluginManagement {
repositories {
maven { url "<Repo_URL>" }
}
}
In my case I had configured a proxy from my job in the gradle.properties file, but I wasn't through their VPN.
If this is also your case, you can just comment the lines in that file, or just connect to the VPN if it is possible.
I could solve it as follows:
In the build.gradle file add the following lines:
Then you must open a command window and enter the folder where you have the project and execute the following order:
gradle build
That's it, with this your error must be solved ... Greetings !!!
None of the answers above worked for me, what fixed it was removing '.RELEASE' from the version (see here)
id("org.springframework.boot") version "2.5.4.RELEASE"
to
id("org.springframework.boot") version "2.5.4"
I had this problem, too. I used the OpenJDK 1.8 in my Spring Boot Project which for whatever reason created these complications, so I changed it to Amazon Corretto JDK 11 and the sync and build ran without errors.
If you use IntelliJ I would recommend you to change your SDK in the Project Structure/Project, Project Structure/Modules and Project Structure/SDKs and finally change the Gradle JVM to the new JDK version in Settings/Build, Execution, Deployment/Build Tools/Gradle/GradleJVM.
You are using incompatable gradle versions!!!
Check your gradle version:
your gradle version: gradle --version
project version: gradle/wrapper/gradle-wrapper.properties has property distributionUrl where you can find project version
If there is difference between your gradle version and project gradle version just download and use project gradle version https://gradle.org/releases/
I had this issue too, after trying out all the above it wasn't resolved. Then by trying gradle with other versions and other version of JDK, then I figured out that it was due to SSL authentication issue. In my case I have to add the security certificates from my local nexus repository to the JDK used by Gradle and the problem was resolved.
You can download the SSL certificates by browsing to the nexus repository manager and downloading it from the browser.
Guys for me was just old Gradle version, I updated following this link https://gradle.org/install/. For Ubuntu:
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-7.0.2-bin.zip
$ ls /opt/gradle/gradle-7.0.2
LICENSE NOTICE bin getting-started.html init.d lib media
Team adding below in build.gradle will help solve the issue:
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
I had the same error. The reason was in my Windows machine path to the java certs in gradle.properties file having in correct format (i.e / instead of \ ) systemProp.javax.net.ssl.trustStore=<JAVA_HOME>\\lib\\security\\cacerts
The default build.gradle file generated by spring.io only includes mavenCentral in repositories. Not sure why, but once in a while, this error shows up. Add jcenter as well in there, it should work.
To be more clear repositories could look like following after change
repositories {
jcenter()
mavenCentral()
}
In my case I was on vpn and it blocked the traffic from above repositories.
First of all you need to understand the problem. Why did this error occur ?
The lines in build.gradle file
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
tells gradle that "spring" and "java" are required for you project to build.
Plugins are task in gradle.
Now for compiling the project the gradle has to bring these plugins specified. for that it
will look in the repositories that you have specified. in
repositories {
mavenCentral()
}
So There must not be any problem with the Code. Refreshing must solve

Gradle Dependency Problem when Upgrading to Gradle 6

I have a gradle Project where I have a dependency on "hudson-core 3.3.3"
compile group: 'org.eclipse.hudson', name: 'hudson-core', version: '3.3.3'
This works without a problem when using Gradle 5.6.2
When I upgrade to Gradle 6.0.1 I receive the following error:
Could not resolve org.eclipse.hudson:hudson-remoting:3.0.3.
Required by:
project : > org.eclipse.hudson:hudson-core:3.3.3
project : > org.eclipse.hudson:hudson-core:3.3.3 > org.eclipse.hudson:hudson-cli:3.3.3
> Could not resolve org.eclipse.hudson:hudson-remoting:3.0.3.
> inconsistent module metadata found. Descriptor: org.eclipse.hudson:hudson-remoting:3.0.4-SNAPSHOT Errors: bad version: expected='3.0.3' found='3.0.4-SNAPSHOT'
The Repository is always the same:
repositories {
mavenCentral()
maven {
url 'http://repo.jenkins-ci.org/public/'
}
}
Any Ideas why this error happens?
As said by #ToYonos, the problem is in the dependency itself.
Not perfect solutions, but 2 workarounds can be done as explained in Gradle's documentation (v6.7.1):
Exclude that transitive dependency, for example in the current Gradle versions using implementation instead of compile:
implementation('org.eclipse.hudson:hudson-core:3.3.3') {
exclude group: 'org.eclipse.hudson'
exclude module: 'hudson-remoting'
}
Override that transitive dependency version:
implementation('org.eclipse.hudson:hudson-remoting') {
version {
strictly '3.0.2' // As 3.0.3 is having the issue
}
}
In the pom.xml file of hudson-remoting 3.0.3, the version is <version>3.0.4-SNAPSHOT</version>
The issue is quite clear.
I tried with an old Gradle 4.4.1 and I am having the exact same issue. Likewise with Gradle 5.1.1 and your version, 5.6.2
I'm quite sure that if you clean your artefact cache for Gradle 5.6.2, it won't work anymore.
The error is on the repository side.
Another option is to define a repository that will download only a jar:
repositories {
mavenCentral() {
name = "Download only jar repo"
metadataSources { artifact() }
content {
// Use this repository only for org.eclipse.hudson:hudson-remoting
includeVersion("org.eclipse.hudson", "hudson-remoting", "3.0.3")
}
}
mavenCentral()
}
Also since pom is not downloaded you would have to add hudson-remoting dependencies by hand to build.gradle. But luckily for this particular case hudson-core already contains the only dependency commons-codec:commons-codec:1.4 that hudson-remoting needs, so this is not needed.
Note: the order of repositories is important, although in that case it will work either way. If you don't want to care about the order when using repositories with filter check exclusive content filtering.

Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not found in any of the following sources

I have a fresh install of IntelliJ, I created a new kotlin gradle project using the following settings:
This produces the following build.gradle.kts, (the exact same file works on my Windows machine):
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Which produces this error, when trying to do a gradle refresh:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not
found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.2.71')
Searched in the following repositories:
Gradle Central Plugin Repository
Check your Internet connection and make sure your Internet is not restricted.
I solved this problem by turning on proxy for all tunnels (not just HTTP) with a VPN app.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
//tasks.withType<KotlinCompile> {
// kotlinOptions.jvmTarget = "1.8"
//}
gradle sync by commenting the above lines. The gradle will be set up.
once the gradle is downloaded, uncomment those line and sync again.
if the dependencies are not downloaded properly, run 'gradle build' in the terminal and click on gradle sync.
This solved the issue for me.
(1) in my case (OpenJDK 11 on Ubuntu 18.04) the problem was Gradle not being able to download the POM file from gradle plugin-server. you can test it by entering this line into jshell:
new java.net.URL("https://plugins.gradle.org/m2/org/jetbrains/kotlin/jvm/org.jetbrains.kotlin.jvm.gradle.plugin/1.3.11/org.jetbrains.kotlin.jvm.gradle.plugin-1.3.11.pom").openStream()
(you can find your url by running gradle with --debug option)
So if you received an exception like this: InvalidAlgorithmParameterException: trustAnchors parameter must be non-empty then the trouble is CA-certs cache. which could be easily fixed by writing these lines into bash Ref:
sudo su
/usr/bin/printf '\xfe\xed\xfe\xed\x00\x00\x00\x02\x00\x00\x00\x00\xe2\x68\x6e\x45\xfb\x43\xdf\xa4\xd9\x92\xdd\x41\xce\xb6\xb2\x1c\x63\x30\xd7\x92' > /etc/ssl/certs/java/cacerts
/var/lib/dpkg/info/ca-certificates-java.postinst configure
By the way do not forget to restart gradle daemon before trying again. (gradle --stop)
(2) another reason could be your internet not having access to bintray.com (the internet of Iran or China) which you can test by putting this line on jshell :
new java.net.URL("https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.3.11/kotlin-gradle-plugin-api-1.3.11.pom").openStream()
If you received a connection timeout, it confirms this theory. In this case you need to buy and have proxy/vpn connected in order to be able to download these dependencies.
Check your gradle and kotlin (or Java) versions.
I got the same error and my issue is solved by specifying the kotlin version in build.gradle:
Before:
plugins {
id 'org.jetbrains.kotlin.jvm'
}
After:
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.4.10"
}
In my case (Ubuntu 20.04), problem was with gradle 7.2, installed from snap.
I have removed gradle 7.2, installed from snap and install gradle 7.2 from sdkman. Works fine for me.
If you are using java like me .I got the issue fixed by adding the following:
Root gradle
dependencies {
ext.kotlin_version = '1.4.10'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
......
}
App gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"
......
}
Ok, so the answer was very simple all along. For some reason I activated gradle's "Offline work" toggle and that was the cause of the problem.
To disable it simply go to Settings > Build, Execution, Deployment > Build Tools > Gradle and deselect the "Offline work" checkbox.
In my case the problem was because Charles Proxy. After closing Charles I could start working again
I updated my Kotlin version to 1.7.20 and fixed this problem.
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
I recently had similar issue with an empty project autogenerated by Intellij Idea.
Solved this problem by combining Java and Gradle versions.
Initially I had Oracle Java 8 with Gradle 6.8.3.
After several attempts I found a working combination - AdoptOpenJDK 11 and Gradle 5.6.4
In my case I changes the Gradle JVM in Settings > Build, Execution, Deployment > Build Tools > Gradle and it worked.
Disconnect from your VPN (or make sure you have an open internet connection), then restart Android Studio.
If you don't restart it sometimes it continues with invalid proxy properties.
This for Ktor devs. If you are working on a ktor application with the web project generator there is a chance the generator sets invalid jvm plugin version. So make sure you are setting correct version for jvm plugin. You can find the latest jvm plugin version here. Here is the sample build.gradle.kts file.
//Plugin section
plugins {
kotlin("jvm") version "1.8.0"
id("io.ktor.plugin") version "2.2.2"
}
//Dependancy section
dependencies {
...
testImplementation("io.ktor:ktor-server-tests-jvm:1.8.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.8.0")
...
}

Gradle: how to use the latest version of a plugin automatically

I have developed an internal plugin. The plugin has its own version. I then use that plugin for a build process in a repository.
If I change the version of the plugin, I have to update the build.gradle to spell our the new version. I have about 100 of these repositories.
Is there a way to specify in my build.gradle to use the latest version of the plugin that can be found in that location?
I could ran a batch file before gradle that find the latest, updates build.gradle with that number and then runs the build process but this is a big work around to a functionality that should be available.
See code below where I call the plugin that I change quite often:
buildscript {
repositories {
maven {
url "c:/git/_TEST/plug-in"
}
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.0'
}
apply plugin: 'com.myplugin.mypluginbuild'
}
if I don't specify the version, it returns an error. Any suggestions?
For those who use plugins{} block, gradle7+ supports dynamic version, which includes + and latest.release.
plugins {
id "your-plugin-id" version "1.0.+"
}
dynamic version doc
It's not possible this way. See the plugins {} block and plugins documentation.
For core plugins you must not provide a version.
For community plugins you have to provide a version.
Maybe script plugins are way to go:
apply from: 'my_script_plugin.gradle'
I have a solution to this question.
The + specified in the version field will do the trick. It will enable gradle to use the latest plug-in automatically.
I.e:
dependencies {
classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.+'
}

could not resolve all dependencies for configuration ':compile'

To study Gradle I am using the book Gradle in action.
There was an example of dependency definition.
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
But when I do in console gradle build I've got an error
What is the problem? My whole .gradle file looks like this
apply plugin: 'java'
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
You did not tell Gradle where to find commons-lang3 library. Easy fix is to add the following to your build script:
repositories {
mavenCentral()
}
Of course you can find this piece of information in documentation - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10608
I was facing this same issue. I fixed it by using local gradle distribution instead of the default gradle wrapper. This is how it goes, make sure that you have Gradle installed and setup(PATH variable).
Open IntelliJ. Goto File->setting->Build, Exec, Deployment->Build tools->Gradle and use local gradle distribution and add your Gradle Home. Apply changes and try to run it now.

Resources