I have multiple modules in my android project. I have one Gradle file which having code for ktlint. I applied that Gradle file to every module by writing this in the project Gradle file.
subprojects { subProject ->
apply from: "$project.rootDir/commonFiles/gradleScript/kotlin-code-quality.gradle"
}
now the problem is I can run ktlint on each module by giving their name in command like this.
Running ktlint for cache module.
./gradlew :cache:ktlint
but I need to run all modules ktlint at once.
Here is my open-source repository and pull request on which I need to perform ktlint action.
Sorry, it's my bad. ./gradlew ktlint will always run on multimodule. I had some lint checks fail in the app module. I thought it is running only on the app module.
but when I fixed the app module's lint and ran the ./gradlew ktlint. it jumped to the cache module.
I hope it helps you Thanks.
Related
What are the differences between
./gradlew :app:dependencies
and
./gradlew :app:androidDependencies
?
All I've been able to notice is that androidDependencies includes .jar and .aar in the output graph. Why is this the case and is there a way to include these files in the dependency output via dependencies?
You can run ./gradlew :app:tasks to see a short description of each Gradle task that is runnable in the :app project. The description that I see for each of the androidDependencies and dependencies Gradle tasks is as follows:
androidDependencies - Displays the Android dependencies of the project.
dependencies - Displays all dependencies declared in project ':app'.
Sadly, the descriptions here don't do a great job of differentiating between the two Gradle tasks. However, on running each of the two Gradle tasks, I see two differences in the output, as follows:
The androidDependencies task calls out whether the library is packaged as an aar or a jar. The dependencies task does not offer this information. (You have already called this difference out in your question.)
The androidDependencies task prints a flattened list of the project's dependencies. The dependencies task, on the other hand, prints a nested graph of the project's dependencies.
A further difference between the two tasks is that you can provide a --configuration option to the dependencies task to restrict its output to a single configuration. For example, if you run ./gradlew :app:dependencies --configuration debugCompileClasspath, this will only display the dependencies for the debugCompileClasspath configuration. The --configuration option is not available for the androidDependencies task.
I have an app with 2 libraries as dependencies. I'm trying to build a script that clones those libraries into an empty folder and build the project.
I created a task within the app's build.gradle that clones the repos:
exec { commandLine "git", "clone", repo, repoFolderName }
The script starts and clones the repos, all fine but when it starts building the app if fails with the following error:
"Could not determine the dependencies of task ..."
If I run the script again it will successfully build the project.
From my initial investigation it seems that Gradle creates the dependencies as the 1st thing, before the libraries are locally cloned so the libraries are not there hence the build fails. If I run it again as the libraries are already there it will successfully build the project.
Any help is much appreciated.
I want to use sync project with gradle file in command line but I dont know how to do
like this :
It besides do ./gradlew build also do other things
For example, in a file is written to a local library name android-test
than in settings.gradle read this file and call include ":${android-test}" .if I use AS sync project with gradle files button,AS can load
module to project , but when I run ./gradlew build, it doesn't work.
But I have developed a plugins, and I want to use this action, so how to call this function ?
Building and syncing from the command line is really simple. In the root of your project you can invoke the gradle wrapper's build command with
./gradlew build
To get a list of all available build tasks for your project:
./gradlew tasks
"./gradlew build" and "./gradlew tasks" in the path of your project.
more commands and steps here:https://developer.android.com/studio/build/building-cmdline.html
The action id is Android.SyncProject, so you can call it in your plugin:
ActionManager.getInstance().getAction("Android.SyncProject").actionPerformed(e);
You can find it in android-plugin.xml, maybe line 161.
Also in SyncProjectAction.java, line 36 you can find its text.
I have an android library project.
I can run the android tests in android studio.
I am not sure how to trigger the tests from the gradle file.
Tried few things but nothing helped. Folder structure is src/main and src/androidTest
Gradle file is below:-
...
sourceSets {
androidTest.setRoot('src/androidTest/java')
androidTest.java.srcDirs = ['src/androidTest/java']
}
Your task for testing should include your flavor and build type.
Firstly, you can check available tasks using
gradle tasks --all
if it fails, check why
gradle tasks --stacktrace
In the output you'll see all the tasks, that are available.
I'm shure that you can run unit-tests, that are under /test folder.
I didn't find the task for running instrumentation tests that are under /androidTest.
If you created unit-tests under /androidTest, I'd recommend you to use
Robolectric and move them to /test folder, it's pretty easy. After that you'll be able to run them with gradle.
When I ran ./gradlew clean for my Android project, the task failed for not resolving all dependencies. The complaints came from the gradle task _debugCompile.
I can verify some of the local dependencies didn't exist which failed the dependencies resolving process, but I'm still curious about why the clean task would check for dependencies while not building the project.
Shouldn't it just delete some directories as mentioned in the following link?
https://docs.gradle.org/current/userguide/java_plugin.html#sec:clean
Is there any gradle built-in task that could just clean the build folder without checking dependency?
Thanks!
Gradle already resolves dependencies during its configuration phase which precedes the execution phase, see The Build Lifecycle (it downloads dependencies only once they are needed, though). However, dependencies being out of date does not make resolution fail. If resolution fails that dependency is likely not available online anymore. If you still have the dependency in your Gradle cache you might be able to work around this by specifying the --offline switch:
$ ./gradlew --offline clean