Task 'jacoocoTestReport' not found in root project - java

I'm trying to find out the line coverage of the JUnit tests in my java program by using gradle and jacoco but the following command causes a failure.
gradle test jacoocoTestReport
The command prints:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'jacoocoTestReport' not found in root project 'ProjectName'. Some candidates are: 'jacocoTestReport'.
* 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.
BUILD FAILED
Total time: 3.389 secs
The build.gradle of my gradle project:
apply plugin: "jacoco"
apply plugin: 'java'
apply plugin: 'application'
repositories {
jcenter()
}
dependencies {
compile 'com.google.guava:guava:20.0'
testCompile 'junit:junit:4.12'
}
mainClassName = 'example.Main'
run {
standardInput = System.in
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}

You have a typo: use
jacocoTestReport
instead of
jacoocoTestReport
(two o's).
Use
gradle tasks
to check what tasks are defined.

You've run an invalid task (double o):
gradle test jacoocoTestReport
instead of:
gradle test jacocoTestReport

Related

Cannot locate tasks that match 'demo:test' as project 'demo' not found in root project 'demo'

error msg
FAILURE: Build failed with an exception.
* What went wrong:
Cannot locate tasks that match 'demo:test' as project 'demo' not found in root project 'demo'.
* Try:
> Run gradlew projects to get a list of available projects.
> 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.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.8'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
spring boot 2.7.8.
java spring quick start guide
I'm unsure how to do this. Can anyone help my troubleshoot this problem? Thanks!

Gradle task --help printed to console instead of my application execution

This is my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.1.11.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example.ProjectJar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
jar {
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes("Main-Class": "com.example.ProjectJar.ProjectJar.FileSend" )
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile 'io.minio:minio:6.0.11'
}
But instead of execution of my main class that does have a main function, I get the following output:
Task :help
Welcome to Gradle 5.6.4.
To run a build, run gradle ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 43ms
What should I do to have my main class execute instead of this?
Try these :
gradle clean build
This command creates the spring-boot jar file to the build/libs directory or the target directory.
we can start our application by running the following command at the command prompt:
java -jar spring-boot-web-application.jar
Another way
./gradlew bootJar
This command creates the spring-boot jar file
To run the application is by executing the following Gradle command:
./gradlew bootRun

Spring Boot Gradle quickbuild that skips the non-essentials

Java 8 and Gradle 4.6 here. I have a Spring Boot app with the following build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
}
}
plugins {
id 'java-library'
id 'checkstyle'
id 'jacoco'
}
apply plugin: 'org.springframework.boot'
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
configurations {
dev
}
dependencies {
compile(
,'ch.qos.logback:logback-classic:1.2.3'
,'org.slf4j:jul-to-slf4j:1.7.25'
,'org.apache.logging.log4j:log4j-to-slf4j:2.9.1'
,'org.apache.commons:commons-lang3:3.7'
,'org.springframework.boot:spring-boot-starter-actuator'
,'org.apache.commons:commons-text:1.2'
,'commons-beanutils:commons-beanutils-core:1.8.3'
)
testCompile(
'junit:junit:4.12'
,'org.mockito:mockito-core:2.23.0'
)
dev('org.springframework.boot:spring-boot-devtools')
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
String buildName = 'myapp'
jar {
baseName = buildName
}
bootRun {
if(project.hasProperty('debugMode')) {
jvmArgs = [ "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" ]
}
classpath = sourceSets.main.runtimeClasspath + configurations.dev
}
checkstyle {
toolVersion = '8.12'
ignoreFailures = false
}
jacocoTestReport {
reports {
xml.enabled false
html.enabled true
html.destination file("${buildDir}/reports/jacoco/")
}
}
check.dependsOn jacocoTestCoverageVerification
jacocoTestCoverageVerification.dependsOn jacocoTestReport
So this is a Spring Boot Java app that also uses the Checkstyle and Jacoco Gradle plugins.
I consider a "full build" to be an invocation that:
Compiles
Runs Checkstyle
Runs unit tests (JUnit)
Runs Jacoco for code coverage analysis
Uses Spring Boot's libraries to build a "fat" (self-contained) executable jar
Given my current Gradle build file, I run a full build like so:
./gradlew clean build
However this can take several minutes to run through all the unit tests and has become cumbersome. I would like to introduce a
"quick build" option that only compiles the code and creates the Spring Boot fat jar for me. This will help speed up development
time tremendously.
I'm hoping to invoke the quick build like so:
./gradlew clean quickbuild
So far I've got this:
tasks.register("quickbuild") {
doLast {
// ???
}
}
But not sure how to link the compilation and fatjar tasks to it (and more importantly; skipping all the other stuff that I don't want!). Any ideas as to what I'm missing?
Update
The bootJar task doesn't seem to exist or be configured (please check my build.gradle file provided above!):
$ ./gradlew clean bootJar
FAILURE: Build failed with an exception.
* What went wrong:
Task 'bootJar' not found in root project 'myapp'. Some candidates are: 'bootRun'.
* Try:
Run gradlew 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
When I try to run bootRun:
$ ./gradlew clean bootRun
It tries to actually run my app! That's not what I want! I just want to compile and build the fat jar!
See documentation from the Java plugin here : https://docs.gradle.org/current/userguide/java_plugin.html#lifecycle_tasks
You could create a new task (quickbuild) and make it depend on the desired task (in your case it could be the assemble lifecycle task, I guess, or maybe bootJar task (for SpringBoot v2.x) or bootRepackage (for SpringBoot v1.5.x) )
tasks.register('quickbuild'){
dependsOn assemble
}
But if the only purpose of quickbuild task is to trigger the creation of the Jar, the simpliest solution is to execute assemble directly
./gradlew clean assemble

gradle build: repo1.maven.org: unknown error

I have a spring-boot app that I was able to start up the server in eclipse.
However, when I goto terminal and do gradle compile, here is the console log i am getting:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'springBootREST'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE.
Required by:
:springBootREST:unspecified
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE.
> Could not get resource 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.2.5.RELEASE/spring-boot-gradle-plugin-1.2.5.RELEASE.pom'.
> Could not HEAD 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.2.5.RELEASE/spring-boot-gradle-plugin-1.2.5.RELEASE.pom'.
> repo1.maven.org: unknown error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
I am not entirely sure why this is happening: it seems like it is having some issues with proxy server, but if I were to do wget I can get the files under repo1.maven...
For reference, this is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
// same as what is in my .bash_profile
systemProp.http.proxyHost='my proxy server'
systemProp.http.proxyPort='my proxy port'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'spring-boot'
group = 'lookupGroup'
jar {
baseName = 'lookupService'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Any idea why I can't build?
Proxy properties should be configured in gradle.properties file as stated in the docs.

Build a project using gradle FAILURE: Build failed with an exception

I am trying to build an opensource project using gradle, but when I run the "gradle clean" command within my local repository directory the following error message appears.
FAILURE: Build failed with an exception.
Where:
Build file '/home/muhammad/OpenSource/iotsys/iotsys/build.gradle' line: 3
What went wrong:
A problem occurred evaluating root project 'iotsys'.
Plugin with id 'maven-publish' not found.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
my "build.gradle" file look like this
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'maven'
group = 'at.ac.tuwien.auto.iotsys'
version = '0.1'
sourceCompatibility = 1.6
repositories(){
mavenCentral()
mavenRepo url: 'https://repository.jboss.org/nexus/content/repositories/releases/', name: 'JBoss Releases'
mavenRepo url: 'https://repository.jboss.org/nexus/content/groups/public/', name: 'JBoss Public' }}
I am new to gradle and maven. Can any one please help me to solve this issue?
The solution is very very simple you just have to run the studio with administrator privileges..
STEPS : -
Right click on the studio icon.
Run as Administrator.
That's it Enjoy..!

Categories

Resources