Trying to run SonarScanner with gradle on the open-source Conversations app - java

To learn about SonarQube I'm using the open-source app called Conversations and I'm trying to run SonarScanner with gradle. I have directly cloned the project from git and added the following configuration in the build.grade:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
}
}
apply plugin: "org.sonarqube"
And when I run the command "gradle sonarqube" in the root folder I get the following error:
Execution failed for task ':compileConversationsPlaystoreSystemDebugJavaWithJavac'.
I don't understand how to run sonarscanner with gradle and would appreciate if someone could point me to the right direction.

Related

MissingPropertyException for Gradle Plugin - Cannot find task type

I am currently in the process of re-organizing and re-structuring some of the projects we use at work.
One of my goals is to integrate a project's unit tests correctly. I have upgraded the root projects Gradle to the latest version (5.6.2) and I have made all the necessary DSL changes.
Right now I'm in the process of including the project's integration tests under its source code. For this I created a new subproject.
So far so good but when I attempt to build the project it fails with following exception:
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'StartServerTask' for project ':integration-tests' of type org.gradle.api.Project.
at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:84)
at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.getMissingProperty(BasicScript.java:156)
at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:61)
at org.gradle.groovy.scripts.BasicScript.getProperty(BasicScript.java:65)
Now, the task in question comes for a Gradle plugin a colleague created in the past. Said plugin is fetched from a maven repository as a dependency like so:
buildscript {
repositories {
maven { url 'maven_link' }
}
dependencies {
classpath 'fts.gradle:start-server:0.3'
}
}
plugins {
id 'java'
id 'application'
id 'eclipse'
}
And applied like
apply plugin: 'fts.gradle'
I have tried almost everything, even changing the package structure of the plugin, but I am unable to include it properly in the build file.
If I copy paste the code directly within the project's build.gradle everything works fine but it doesn't so if I try to remote fetch and include the plugin.
Can anyone provide any insight to this?

Error : Connection timed out: connect ? While building project gradle

I am getting error while building the gradle (IDE tool version 3.1.3 android)
android version : 3.1.3
gradle version : 4.4
Not able to download files below when gradle sync
Download https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom 21s 215ms
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom 1m 24s 138ms
Download http://maven.google.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom 21s 84ms
Error : Connection timed out: connect
Please help me to solve this problem
Are you working behind a proxy?
try to run
./gradlew assemble --debug --info --stacktrace
And share your log information please.
Besides that, check your gradle.properties to see if you have any proxy configured? If you are not behind any proxy, please remove those settings.
Also, please be sure that "google()" repo is added and put as the first inside your buildscripts block. E.g.
buildscript {
repositories {
//jcenter() //Should remove this repository for Android Gradle Plugin 3.0+, and use google() repository as shown below
google()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

Gradle build doesn't download dependencies

After running gradle build in the root directory of my web app, the spring security dependency declared in build.gradle does not get downloaded.
here is my build.gradle
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'hombod' at '7/19/16 4:19 PM' with Gradle 2.14.1
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
compile 'org.springframework.security:spring-security-web:4.1.1.RELEASE'
}
instead, I just get this message
:compileJava UP-TO-DAT
:processResources UP-T
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO
:processTestResources
:testClasses UP-TO-DAT
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
This is a spring mvc web app that I ran the gradle init command in
System caches the dependent jars so it won't be downloaded again and again.
If your goal is to just see the downloads of the dependencies then you can force it to redownload.
Remove any dependency caches stored locally [1]
$ rm -rf ~/.gradle/caches/
Then restart your build
$ gradlew clean build
You could also force a dependency update with [2]
$ gradlew --refresh-dependencies
[1]https://docs.gradle.org/current/userguide/dependency_management.html#sec:dependency_cache
[2]https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh
The solution that helped in my case:
File -> Invalidate Caches/Restart...
I'm using IntelliJ 2018.2.3 and Gradle was not downloading dependencies for me.
I found that I had to uncheck the 'Offline work' box in the Gradle settings to get it to download them. I'm not sure how this box became checked because I didn't check it (honest).
EDIT: In IntelliJ 2021.2.1 Offline Mode can now be toggled in the Gradle tool window, as shown below:
If your project builds successfully some time it may be gradle download problem with a current proxy.
Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it. Your problem is setting up the proxy. You just need to set some variables in $projectDir/gradle.properties, for example:
#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
This can be used to download dependencies without proxy. If you want to use a proxy for you can use the code as below instead of above code.
systemProp.https.proxyPort=3128
systemProp.http.proxyHost=192.168.16.2
systemProp.https.proxyHost=192.168.16.2
systemProp.http.proxyPort=3128
Proxy port and host can be changed as you want.
had something like this problem while was building older react-native project.
the react-native run-android command just did print:
Could not find com.android.tools.build:gradle:2.3.3
after lot of changes to the build.gradle file noticed that it was okay and
just opened the android directory of my react-native project in Android-Studio and all dependencies was downloaded.
but to prevent download of files again and again used GradleCopy to make them available offline and changed the build.gradle file like below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
//kotlin_version = '1.2.40'
offline = 'D:/android/sdk/extras/m2repository'
}
repositories {
try { maven { url uri(offline) } } catch (Throwable e) {}
try { maven { url uri('C:/Program Files/Android/Android Studio/gradle/m2repository') } } catch (Throwable e) {}
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3' //was "2.3.3" with "gradle-3.4.1-all.zip" got "3.1.3" with "gradle-4.4-all.zip"
////below "kotlin" is required in root "build.gradle" else the "offline" repo will not get searched
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
try { maven { url uri(offline) } } catch (Throwable e) {}
jcenter()
mavenLocal()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
(i.e. did set offline variable to my m2repository path and used it like: maven { url uri(offline) })
Choosing a right log level [1] will allow you to see what is happening behind.
-i/--info will show you whether gradle has used the cached dependency or the dependency downloaded.
gradle clean build -i
https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level

Gradle maven plugin: uploadArchives cannot find /tmp/gradle_empty_settings xml

I just switched from Eclipse and Maven to Android Studio and Gradle for my Android projects.
Now I would like my Jenkins server to build and upload release versions to my self hosted Nexus server.
For this I added those lines to my build.gradle
apply plugin: 'maven'
group = "de.myapp"
version = '2.2.0'
android {
...
}
uploadArchives {
repositories {
mavenDeployer {
maven {
name "snapshot_repo"
url "http://192.168.178.85:8081/nexus/content/repositories/myapp_snapshots"
credentials {
username "admin"
password "admin123"
}
}
}
}
}
The building process works fine but I can't upload any project to the Nexus server without getting this strange message:
:myapp_testname:assembleDebug
:myapp_testname:uploadArchives
Upload http://192.168.178.85:8081/nexus/content/repositories/myapp_snapshots/de/myapp/myapp_testname/2.2.0/ivy-2.2.0.xml
Upload http://192.168.178.85:8081/nexus/content/repositories/myapp_snapshots/de/myapp/myapp_testname/2.2.0/ivy-2.2.0.xml.sha1
[ant:null] Error reading settings file '/tmp/gradle_empty_settings56173630026020664.xml' - ignoring. Error was: /tmp/gradle_empty_settings56173630026020664.xml (No such file or directory)
BUILD SUCCESSFUL
Total time: 3 mins 31.555 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
Archiving artifacts
Finished: SUCCESS
I will get two ivy files on the repository but nothing more.
It seems like gradle cannot create the tmp file. But I don't know why.
When I execute this on my local windows machine I will get the same error (just with another tmp folder)
Does anyone know how to solve this issue?
Well, I just found the problem and the solution:
I'm using several flavors and buildTypes (free/premium and debug/release) in my app.
This means there is no real "default" variant.
In this case you need this line in your module's build.gradle to publish your different build types
android {
...
publishNonDefault true
...
}

Gradle Maven plugin "install" task does not work with Android library project

I want to install android library project to local maven repository.
Here is build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
version = "1.0.0-SNAPSHOT"
group = "com.example"
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
When I run:
gradle install -i
it gets stuck here:
Executing task ':project:installTest' due to:
Task has not declared any outputs.
Starting process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''. Working directory: D:\Projects\java\....... Command: d:\android-sdk-windows\platform-tools\adb.exe install -r D:\Projects\java\.......\build\apk\project.apk
An attempt to initialize for well behaving parent process finished.
Successfully started process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''
> Building > :project:installTest
So first thing I noticed is that it's trying for some odd reason to deploy it on a device as APK.
Am I doing something wrong or is it just android-library plugin not compatible with maven plugin?
Edit: Please refer to the github page (https://github.com/dcendents/android-maven-gradle-plugin) for the latest instructions and find the correct version to use. The original instructions are not suitable anymore with the latest gradle release.
Original Post:
I've modified the maven plugin to be compatible with android library projects. See the project on github: https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
Then you should be able to install aar into your local maven repository using the install task.
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.
Elaborating on CyclingSir's answer, I propose to add a separate "installArchives" task. This should also take care of picking up your custom artifacts (e.g. sources).
apply plugin: 'maven'
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: repositories.mavenLocal().url
}
}
}
Note that with Gradle Android plugin v0.5.5, gradle install still tries to install something on a device.
There's an easier solution if you don't want to use a custom plugin. Instead, just recreate the install task with a different name. I called it installArchives. Add the following code to your build.gradle:
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
repositories.mavenInstaller {
configuration = configurations.default
pom.groupId = 'my.group'
pom.artifactId = 'my-artifact'
pom.version = '1.0.0'
}
}
You can now run gradle installArchives to install your aar locally.
UPDATE 2014-11-26
The answer below made sense at the time of writing, when Android Build Tools were at version 0.5.5. It is most likely outdated now and probably does not work anymore.
I have personally switched my projects to use android-maven-plugin as described in the answer above, the plugin works fine with the recent versions of Android Build Tools too.
THE ORIGINAL ANSWER FROM FEBRUARY 2014
Publishing as AAR
If you don't mind using an older version of com.android.tools.build:gradle (i.e. 0.5.4), you can use the approach described in this blogpost. Not that according to the discussion in adt-dev mailing-list, this does not work in 0.5.5.
Add the following lines to your build.gradle:
apply plugin: 'maven-publish'
// load bundleRelease task
// this will not load the task in 0.5.5
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
Publishing as JAR
If your Android Library does not have custom resources and can be published as JAR, then you can use the following build.gradle that works even with 0.5.5.
// build JAR file
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/classes/release/"
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact androidReleaseJar
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
I just solved the issue by defining an upload archive as described here:
Gradle documentation 52.6.2. Deploying to a Maven repository
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
calling
gradle uploadArchives
deploys the artefact to the (in my case local) Maven repo.
I havn't found a simple and more flexible way to specify the local repo's url with e.g. mavenLocal() yet but the above suits my needs.

Categories