gradle dependencyUpdates failure - gradle

I have "installed" or included ben manes - gradle versions plugin:
https://github.com/ben-manes/gradle-versions-plugin
The code below is the build.gradle (Project: rewards)
apply plugin: "com.github.ben-manes.versions"
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.ben-manes:gradle-versions-plugin:0.20.0"
}
}
When I try to run the following gradle Task: gradle dependencyUpdates.
I get the following :
FAILURE: Build failed with an exception.
What went wrong:
Task 'gradle' not found in project ':app'. Some candidates are: 'bundle'.
Try:
Run gradle tasks to get a list of available tasks. 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 0s
11:23:53: Tasks execution finished 'gradle dependencyUpdates'.

After further testing, I realised that the task that I need to run should not have the word gradle in front. The command line instruction should just be dependencyUpdates. Then click on okay and it will export the report.

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'
}

Flutter apps not running on android

Applications are not running on android but running well on ios, error says that there is a problem in gradle although native android projects run well in android studio, I tried google and other threads on stackoverflow with no luck.**
N.B: the error occurs regardless the project, it always happens even with newly created projects in flutter. Thanks
* Error running Gradle:
ProcessException: Process "/Users/apple/Documents/flutter_work/tqtqt/android/gradlew" exited abnormally:
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.10.2/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error: Could not find or load main class org.gradle.launcher.daemon.bootstrap.GradleDaemon
* 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
Command: /Users/apple/Documents/flutter_work/tqtqt/android/gradlew app:properties
Please review your Gradle project setup in the android/ folder.
build.gradle
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Try to run flutter clean on project folder and run it again.

Gradle dependency management plugin

I am trying to run the following minimal gradle build file including the dependency management plugin:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
But then running gradle fails:
* What went wrong:
Plugin [id: 'io.spring.dependency-management', version: '1.0.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 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.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.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings
Is there a missing dependency in the gradle file?
The plugin cannot be found because you defined repositories inside your build script and tried to use plugin outside it. Remove buildscript or add repositories for your build file also.
(Dependencies and repositories defined inside build script are accessible in that buildscript scope)
Example:
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}

Getting spring boot jar files through gradle

The spring framework wants users to use dependency tools to download the framework, so I am trying to use gradle. I got this sample from their website http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto
buildscript {
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
jar {
baseName = 'root'
version = '0.0.1-SNAPSHOT'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
I saved this to a file called build.gradle. Then in the CMD I went to the directory where the build.gralde file is located and type:
gradle build
It seemed to run fine but towards the building it's not working, here is the last logs I got from the command prompt:
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRepackage'.
Unable to find main class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 9.664 secs
I don't understand this "> Unable to find main class". I only want to get all the jar files and put them inside WEB-INF/lib of my eclipse projects. I am extremely new at gradle. What should I do?
It's not really clear to me, acoording to your comments, what are you trying to achieve, if you don't have a project sources, but for some reason wants to download dependent libraries. Gradle doesn't work this way, all the libraries are dowloded on demand, that means, they are dowloaded then you, for example, try to build your source files.
The exception you get, means, that gradle spring boot plugin's task bootRepackage Didn't find a main class in your project. This main class is mandatory for this task, since the task creates a standalone executable jar.
Sure, it is possble to dowload deps by custom task, like:
task getDeps(type: Copy) {
from sourceSets.main.runtimeClasspath
into 'runtime/'
}
But it seems, that you don't properly understand, how does it work. You should try to read gradle user guide first and let gradle to build your project for you, but not just combine some libs.

Migrating maven checkstyle to gradle

I'm trying to migrate from maven to gradle, having a weird error with checkstyle.
buildscript {
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'checkstyle'
jar {
version = '0.1.0-SNAPSHOT'
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.3.RELEASE'
}
}
dependencies {
checkstyle 'com.puppycrawl.tools:checkstyle:6.10.1'
compile('org.springframework.data:spring-data-commons')
testCompile('junit:junit')
testCompile('org.mockito:mockito-core')
testCompile('nl.jqno.equalsverifier:equalsverifier:1.7.5')
}
test {
maxParallelForks = 4
}
here's the error I'm getting
gradle build slave-vi
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':checkstyleMain'.
> Unable to create a Checker: unable to read /home/xenoterracide/IdeaProjects/entity-api/config/checkstyle/checkstyle.xml - unable to parse configuration stream - Property ${checkstyle.cache.file} has not been set
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.688 secs
How can I get gradle working with the latest version of checkstyle? worth noting my checkstyle.xml did work with maven checkstyle 6.10.1 and 6.8
I found this in my configuration
<property name="cacheFile" value="${checkstyle.cache.file}"/>
I don't remember adding it, maybe it's part of the sun configuration file, and just happens to get filled in by the maven plugin.
The problem here is that you are using checkstyle plugin but you are not specifying any configuration for it.
Here you should add
checkstyle {
ignoreFailures = true
configFile = file("/home/jenkins/scripts/checks.xml")
}
and you should have your checkstyleing file in above mentioned location(You can change to whatever you want).
Here is the sample gradle file with checkstyle, PMD, findbugs, jacoco etc.
http://www.scmtechblog.net/2016/01/sample-gradle-file.html
You can add the information to your build.gradle to make use of it.

Resources