Gradle: how to include external project dependency in IntelliJ? - intellij-idea

I have got two projects:
Project_A
core
other
and
Project_B
foo
These are two separate projects hosted in two different git repositories. Project_B/foo has a SNAPSHOT-dependency on Project_A/core. I use IntelliJ as IDE. We publish snapshots of Project_A/core whenever there is change that needs to be propagated to Project_B/foo. Sometimes the change rate in Project_A/core is so high that it would save a lot of time to have them in one IDEA project so that we can navigate back and forth and the changes are visible without publishing snapshots.
How can I mount these two projects as one project in IDE? I have tried the following:
configurations.all {
resolutionStrategy.dependencySubstitution.all { DependencySubstitution dependency ->
if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.group == "bar.com" && dependency.requested.module == "core") {
def targetProject = findProject(":${dependency.requested.module}")
if (targetProject != null) {
dependency.useTarget targetProject
}
}
}
}

Related

How to customize WAR plugin in subproject in Gradle build script (Kotlin)

I create a Gradle project with several sub-modules, and one module needs war plugin, I just want to customize the web app directory, but the code does not work:
apply {
plugin("war")
plugin("org.gretty")
}
// cannot work
tasks.getByName("war") {
from("src/main/webfiles")
}
// cannot work either
tasks.war {
webAppDirName = "src/main/webfiles"
}
//... other code
This is how I code in the sub-project subproject.gradle.kts file, How to solve this? Thanks for any help!
Solved with the code:
configure<WarPluginConvention>{
webAppDirName = "src/main/webfiles"
}

Check for dependencies update with kotlin-dsl

This question has already been asked before, however the solution is still unknown... Kotlin DSL build scripts dependency updates
With the new implementation of kotlin-dsl. Now the imports looks like this.
implementation Koin.core
implementation Koin.android
and the buildSrc.
object Versions{
const val koin = "2.0.1"
}
object Koin {
val core = "org.koin:koin-core:${Versions.koin}"
val android = "org.koin:koin-android:${Versions.koin}"
val scope = "org.koin:koin-androidx-scope:${Versions.koin}"
val viewModel = "org.koin:koin-androidx-viewmodel:${Versions.koin}"
val extension = "org.koin:koin-androidx-ext:${Versions.koin}"
val test = "org.koin:koin-test:${Versions.koin}"
}
in this case Koin is using a previous version, but i know that there's a new version https://github.com/InsertKoinIO/koin
anyone knows how to check if the dependencies has a newer version with kotlin-dsl?
I've tested this Gradle Dependencies Update Check Plugin on my Android/Kotlin DSL build (with a separate Versions class with versions definitions) and it works fine for me:
CheckDependencyUpdates Gradle Plugin
(I've also tested that it works with a traditional Groovy-DSL project)
To install the plugin (copied from linked page) add the following to your build.gradle.kts. Note that I've removed the version number from this as it will, unlike the page I've linked to, get out of date:
plugins {
id("name.remal.check-dependency-updates")
}
To run the update check (copied from gradle tasks) run the following:
gradle checkDependencyUpdates
You will see an output section similar to the following:
New dependency version: com.android.tools.build:aapt2: 3.6.1-6040484 -> 3.6.3-6040484
New dependency version: com.android.tools.lint:lint-gradle: 26.6.1 -> 26.6.3
I made this plugin. Dependency Updates Commenter.
Just apply plugin and add annotation to the dependency properties and execute commentDependencyUpdates task. This is the example:
object Junit {
const val junit = "junit:junit:4.12"
}
import io.github.zeroarst.dependencyupdatescommenter.CommentUpdates
object Junit {
// Available versions:
// 4.13-rc-2
// 4.13-rc-1
// 4.13-beta-3
// 4.13-beta-2
// 4.13-beta-1
#CommentUpdates
const val junit = "junit:junit:4.12"
}

How do I list only the custom tasks in a Gradle build file?

I have written a gradle build file which several custom tasks. They are all like the following:
task runThis(type:JavaExec) {
doSomething()
}
When I enter "gradle tasks" in a terminal, none of the tasks I have written myself are listed. Only the standard list of tasks which appear when I run this command against a new project.
How do I get the tasks to be listed? And is it possible to print ONLY the custom written tasks?
I think
gradle tasks --all should works, and your customized tasks are in Other tasks category.
In intellij, there is a panel called Gradle projects.
only the custom tasks:
I write a simple task to do the trick:
// run with `gradle printTasks`
task printTasks << {
project.tasks.collect {
task ->
if (!task.group && task.name !='printTasks') {
println task.name
}
}
}

Map Plugin shows no service providers

I'm trying to render an empty Map in QML 5.7, in order to draw geolocated polylines. However, no plugins are available to supply the map data:
Map {
anchors.fill:parent
plugin: Plugin {
name: "osm"
Component.onCompleted: console.log('a',availableServiceProviders.length)
}
MapPolyline {
line.color: "#299FE7"; line.width: 3
path: parent.points
}
Timer {
running:true; interval:1000
onTriggered: console.log('b',parent.supportedMapTypes.length)
}
}
The above outputs:
qml: a 0
qml: b 0
Why don't I have any plugins available, and how can I get one to work?
You don't have a default provider because Qt does not enforce the usage of a specific one. Even more now that all of the available ones require a registration (and the acceptance of an agreement/ToS) to use their services.
The list of available plugins can be found here.
Following the links you can read about the specific setup for the usage of each one.
Adding a provider in QML is just a matter of declaring a Plugin type, something along the line of that:
Plugin {
name: <provider_name> // { "here" | "mapbox" | "osm" }
PluginParameter { name: <param_name>; value: <param_value> }
// other parameters
}
The very same task can be carried out in a C++/non-QML project via QGeoServiceProvider class.
Mind that the access to MapQuest changed few months ago, breaking the Open Street Map plugin. You now need credentials to access their service, e.g. read this comment. The relevant patch has been pushed and merged, as stated in the bug report page of last linked comment, and will be available in Qt 5.6.2 (and Qt 5.7.1) patch release.

Gradle copy creates an empty file

I have a multi-project gradle build that copies some source files from the parent project into the build directory and then attempts to overwrite a token in one of the copied files. Everything runs OK but the file ends up being empty. Here's the file snippet with the template to replace:
---
# file: clients.yaml
#properties shared by all client machines
jmeter_version: "${jmeterVersion}"
Here's snippet of gradle.properties:
jmeterVersion=3.0
And here are two tasks that suppose to do the trick
/** This task copies files from pdo-shared */
task copyFromCommonProject(type:Copy, dependsOn: configurations.commonProjectContent){
from configurations.commonProjectContent.collect{ zipTree(it) }
into "$buildDir"
/*doLast {
updateAnsibleTokens.execute()
}*/
}
task updateAnsibleTokens(type: Copy, dependsOn: copyFromCommonProject) {
from "$buildDir/commons/ansible/group_vars/clients.yml"
into "$buildDir/commons/ansible/group_vars/"
expand(jmeterVersion: "$jmeterVersion")
}
I run this from the parent project as gradle clean :tpcds-benchmark:updateAnsibleTokens
First tasks copies all the files where and as expected it's the 2nd task that does not work
Please notice commented out doLast section. I tried to run these two tasks as gradle clean :tpcds-benchmark:copyFromCommonProject by uncommenting doLast section and removing dependsOn: copyFromCommonProject from the 2nd task
In both instances client.yml ends up completely empty
P.S. Even if I disable expand(jmeterVersion: "$jmeterVersion") line I will get an empty file. With some more tests it seems that copying a file on itself will generate an empty file so perhaps I'm just doing it wrong. The same code I have will work if I only change the destination directory
Basically I had to reread this manual section to understand the lifecycle better.
Following my original example here's 2 tasks that will work as intended. The problem as I started to suspect was that attempt to copy and modify client.yml was happening in the configuration cycle before the actual copying from the source was happening. Adding << for the 2nd task ensured that the modification was happening in the execution cycle after the original file was copied
/** This task copies files from pdo-shared */
task copyFromCommonProject(type:Copy, dependsOn: configurations.commonProjectContent){
from configurations.commonProjectContent.collect{ zipTree(it) }
into "$buildDir"
}
task updateAnsibleTokens(type: Copy, dependsOn: copyFromCommonProject) << {
from "$buildDir/commons/ansible/group_vars/clients.yml"
into "$buildDir/commons/ansible/group_vars/"
expand(jmeterVersion: "$jmeterVersion")
}
I am not sure, why adding the << helped. Nevertheless, doing expand while extracting archive feels much more natural:
task copyFromCommonProject(type:Copy, dependsOn: configurations.commonProjectContent) {
from configurations.commonProjectContent.collect {
zipTree(it)
}
exclude "commons/ansible/group_vars/clients.yml"
with copySpec {
from configurations.commonProjectContent.collect {
zipTree(it)
}
include "commons/ansible/group_vars/clients.yml"
expand(jmeterVersion: "$jmeterVersion")
}
into "$buildDir"
}