gradle: No tests found for given includes: [ro.idea.ToggleTest.testIsAd] - java

This is my screencast and my code, see my screencast, i use standard testSrc and i can run gradle test succeed, but when i run gradle test --test ro.idea.ToggleTest.testIsAd, it failed.
my question is: How to fix it?
In settings.gradle, i set following code:
include ":ro"
project(':ro').projectDir = file("../ro")
my guess it's reason cause this error, but i don't how to fix it

Related

How to run Sbt in IDEA with Merging?

When I run the build in TeamCity with command:
;set test in assembly := {};clean;compile;flywayClean;flywayMigrate;assembly
I get merge errors:
TraceEvent(Error, java.lang.RuntimeException: deduplicate: different
file contents found in the following:
/home/teamcity/tcagent/system/sbt_ivy/cache/org.joda/joda-convert/jars/joda-convert-2.2.1.jar:module-info.class
/home/teamcity/tcagent/system/sbt_ivy/cache/com.fasterxml.jackson.core/jackson-databind/bundles/jackson-databind-2.11.0.jar:module-info.class
/home/teamcity/tcagent/system/sbt_ivy/cache/com.fasterxml.jackson.core/jackson-annotations/bundles/jackson-annotations-2.11.0.jar:module-info.class
/home/teamcity/tcagent/system/sbt_ivy/cache/com.fasterxml.jackson.core/jackson-core/bundles/jackson-core-2.11.0.jar:module-info.class
However, when I do this locally in IDEA, I don't get such errors.
Probably Idea runs sbt without merging. How can I fix this to get the same errors in Idea?
I created sbt task in IDEA with command:
;set test in assembly := {};clean;compile;assembly
and it worked.

Error during SonarScanner execution after executing SonarScanner.MSBuild.exe end command

Sonarqube Version -7.9.5
SonarQube Scanner - sonar-scanner-msbuild-5.0.4.24009-net46
Source code contains - C#, angular.js, html5, javascript.
Hi,
I executed the following commands and after executing the 3rd command I am getting execution failure error.
The command I executed in the CMD prompt are browsing to the path where solution is present are,
SonarScanner.MSBuild.exe begin /k:"Demo" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="TokenID_ABC"
MsBuild.exe /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="TokenID_ABC"
ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
I found one similar kind of issue reported where it is said that due to .java file present in the code the issue occurs, in our code as well .java files are present, not sure the use of them. How can I exclude those .java files while SonarQube analysis is performed and in which file do I need to add exclusion code?
Also, if there is some another solution to resolve this issue, then please let me know as I have very limited knowledge of Sonar.
Link of similar issue -
https://community.sonarsource.com/t/error-while-running-sonar-scanner-please-provide-compiled-classes-of-your-project-with-sonar-java-binaries-property/30027/2
You can exclude arbitrary files by going to your project settings in SonarQube -> Analysis Scope -> Source File Exclusions. Use regex to match your java files, i.e. *.java.

Gradle - What is a non-zero exit value and how do I fix it?

I am developing an Android application, and every time I run it, I get this message:
:module:someTask FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':module:someTask'.
> some message here... finished with non-zero exit value X
* 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: Y.ZZ secs
I have already tried cleaning and building the project, but the error persists.
I have seen answers that say to enable Multidex or increase the heap size, but I am sure I don't need either solution.
What can I do to solve this?
About this question: This is a direct extension of What is a stack trace, and how can I use it to debug my application errors? except you are looking at a Gradle stack trace instead of a Java stack trace.
Foreword
That error message is not enough information to diagnose the problem. There are ways to get more information, and that should be inspected first.
The Gradle output itself should point at the actual error in the few lines above that message between :module:someTask FAILED and the last :module:someOtherTask. Therefore, if you ask a question about your error, please edit your questions to include more context to the error.
The problem
The someTask part of the app:someTask FAILED is very important as it tells you exactly which step of the build process has crashed.
These steps include preparing dependencies, generating and merging the assets and resource files, checking the code for errors and compiling, then finally installing the app.
If at any point of the build process Gradle detects an anomaly, it will throw a non-zero exit value indicating an error has occurred.
The exit value itself is somewhat important.
1 is a just a general error code and the error is likely in the Gradle output
2 seems to be related to overlapping dependencies or project misconfiguration.
3 seems to be from including too many dependencies, or a memory issue.
There are probably others, so please feel free to provide your own comments or answers with other values.
The solution
The general solutions for the above (after attempting a Clean and Rebuild of the project) are:
1 - Address the error that is mentioned. Generally, this is a compile-time error, meaning some piece of code in your project is not valid. This includes both XML and Java for an Android project. Refer to the image for all the things going into the app
2 & 3 - Many answers here tell you to enable multidex. While it may fix the problem, it is most likely a workaround. If you don't understand why you are using it (see the link), you probably don't need it.
If you are unable to find any error output in the Gradle log, then the recommended course of action would be to open Gradle window of Android Studio.
Open up the Tasks folder for each module and perform some combination of the following.
To clean and reset the code of generated files, use build > clean followed by build > build.
To inspect nested dependencies, use help > dependencies. Make sure none are duplicated.
To check your code for syntax errors and warnings, run verification > lint. This will output an HTML file that you can read in your browser. The Gradle logs will say Wrote HTML report to file:///path/to/app/build/outputs/lint-results.html, so just open that file to see all the errors and warnings.
To try and run the app on a device, use install > installDebug.
Additional notes
I've seen many post with value 2 when just installing Android Studio and there is an error
'android-studio/jre/bin/java' finished with non-zero exit value 2
Installing the Java JDK and correctly configuring Android Studio to use the JDK seems to fix this issue.
If you are using the Google Play Services by compile 'com.google.android.gms:play-services:X.Y.Z', then only include the dependencies you actually need, otherwise you most likely did hit the Multidex limit. See how to enable it.
If you have a line in your Gradle file that reads compile fileTree(dir: 'libs', include: ['*.jar']), then you don't need any other line that has compile files('libs/some_file.jar') because that first way says "include every JAR file in the libs/ directory."
Along with that point, if you are using Gradle and are able to find the dependencies that you would like to use by searching the Maven Repository, then it is strongly encouraged to use that instead of manually placing JAR files into the libs/ directory. For each library on that site, there is a Gradle tab and you just need to copy that one line and put compile <line you copied> into the dependencies section.
If you have a line that compiles another project such as compile project(":project_name"), then make sure you aren't duplicating dependencies from there.
Another solution for memory-related issues involves expanding the heap size, which is done from the build.gradle like so
android {
// Other stuffs
dexOptions {
javaMaxHeapSize "2g" // or "4g" if your device has enough memory
}
}
A non-zero exit value is like a check engine light. It simply tells you that something went wrong. You still need to do further diagnostics to figure out what the problem is exactly. To start, you should scroll up in the output from Gradle and see if there is anything else that gives more specific details about what went wrong.

How can you override an existing Gradle plugin from a local repository?

I am building an application using Gradle, JDK 8, Java FX, and Test FX. I need to be on JDK 8 for our application to work on all platforms with our tech stack. My problem is that I am unable to get code coverage into our build. I found this link...
https://github.com/jacoco/jacoco/issues/74
...and using the Jacoco preview build at the top, I was able to replace my intellij JARs and successfully run my tests and get the coverage. However, I am having trouble putting this into my build.gradle. From what I can tell, I need to add a local repository in my build script...
...
apply plugin: "jacoco"
...
buildscript {
repositories {
// Local Repo
// MVN Repo(s)
}
dependencies {
// Classpaths
}
}
jacoco {
toolVersion = "0.6.4.201311160552" // I need this specific version, which isn't on a MVN repo
}
...I tried to add my local repo several ways including...
flatDir(dirs: "lib")
flatDir dirs: "${projectDir}/lib"
maven { url uri("lib") }
one or two other ways I forget
...my lib folder contains the exact contents, unchanged, from the preview build zip's lib folder in the link above. It doesn't seem like gradle is having a problem locating the local repo, but it is having trouble finding the JAR. I assume there is something wrong with the way I am naming it or the way that it is "packaged". I have tried modifying the JAR names but I keep getting the error...
What went wrong:
A problem occurred configuring root project 'myProject'.
Could not resolve all dependencies for configuration ':classpath'.
Could not find :org.jacoco.agent:.
Required by:
:myProject:unspecified
...any ideas why my JAR is not being found? Thanks!
"Answering" my own question, despite the fact that I still haven't quite figured it out. Anyways, here are two links I found that seem to solve my problem...
http://forums.gradle.org/gradle/topics/jacocotestreport_is_skipping
...following some of these instructions allow my tests to run, but I am still not able to run "gradle jacocoTestReport" without it failing.
UPDATE
OKAY! I figured it out, the link above did help me figure it out. My problem was with the asm-all JAR, since there were several, I did not know which one to use. In order to get jacoco working with Java 1.8, you do not need to specify the toolVersion property. All you need to do is add the following to your dependencies block (not the buildscript block, the code block)...
jacocoAgent files(
"$projectDir/lib/org.jacoco.agent-0.6.4.201311160552.jar")
jacocoAnt files(
"$projectDir/lib/org.jacoco.ant-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.core-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.report-0.6.4.201311160552.jar",
"$projectDir/lib/asm-all-5.0_BETA.jar")
...where the asm-all-5.0_BETA.jar is taken from the org.ow2.asm group found at...
http://mvnrepository.com/artifact/org.ow2.asm/asm-all/5.0_BETA
...hope this helps!
for reference, latest jacoco libs are changed so i'm sharing the following snippet:
dependencies{
jacocoAgent files("$rootProject.projectDir/lib/org.jacoco.agent-0.8.3.201904130250.jar")
jacocoAnt files("$rootProject.projectDir/lib/org.jacoco.ant-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.core-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.report-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/asm-7.0.jar",
"$rootProject.projectDir/lib/asm-tree-7.0.jar",
"$rootProject.projectDir/lib/asm-commons-7.0.jar"
)
}

How to make Gradle compile Groovy tests before Java tests

The Groovy plugin for Gradle claims that it "supports joint compilation, which allows to freely mix and match Groovy and Java code, with dependencies in both directions".
However, I don't think this applies to test code.
I have a Java 'sample' test in src/test/java... which uses a class which is located in src/test/groovy.
When trying to build with Gradle, I get an error like this:
SwingJavaFXSampleAppTestInJava.java:23: error: cannot find symbol
SwingJavaFXSampleAppTest swingJavaFx = new SwingJavaFXSampleAppTest();
Notice that SwingJavaFXSampleAppTest is a Groovy class that has not been compiled yet (in the Gradle output I can see that it did not run the compileTestGroovy before it tried compileTestJava because the former depends on the latter).
I am able to build this same project with Maven using the groovy-eclipse plugin.
Why does it not work in Gradle when it claims to support compilation in any order, and how can I make it work?
As explained in the Gradle User Guide, only code passed to GroovyCompile tasks is joint-compiled. So either you put both Java and Groovy code into src/main/groovy, or you reconfigure the source sets:
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs = ["src/main/java", "src/main/groovy"]
For tests, replace all occurrences of main with test.
You should be able to move your java tests into src/test/groovy.

Categories

Resources