Intellij-idea gradle sub-module keeps forgetting root project dependency - intellij-idea

I have two gradle projects defined like so
apiclient (root)
| src\
| build.gradle
|--- android (module)
| src\
| build.gradle
These projects are not on maven, yet, and the module apiclient.android depends on the root module (apiclient).
I keep adding apiclient using the project structure... -> dependency dialog and the reference keeps getting removed from the .iml file whenever I click refresh in the gradle tool window.
how can I keep the child module from forgetting the parent module dependency?
edit: as requested the build.gradle files.
apiclient build.gradle
group 'emby.apiclient'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.guava:guava:18.0'
compile 'org.java-websocket:Java-WebSocket:1.3.0'
}
apiclient.android build.gradle
group 'emby.apiclient'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.code.gson:gson:2.5'
compile 'com.mcxiaoke.volley:library:1.0.16'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'emby.apiclient:apiclient:1.0-SNAPSHOT'
}
The last line compile 'emby.apiclient:apiclient:1.0-SNAPSHOT' is underlined red in the gradle project window. I've tried compile project 'apiclient' as well and the outcome is unchanged.
settings.gradle
rootProject.name = 'apiclient'
include 'android'
findProject(':android')?.name = 'emby.apiclient.android'

In the /android build.gradle file, you need to add compile project(":apiclient") to your dependency list. I found out the hard way that IntelliJ's "Do you want to add a dependency to classpath" dialog only adds it to the .iml file, which isn't run as part of the build.

Related

Declare a bundled plugin as a dependency in IntelliJ IDEA Plugin

Non bundled plugins are stored in the repository and can be referenced by groupId:artifactId:versionId but the documentation only says this ambiguous thing about declaring dependencies on bundled plugins:
locate the plugin’s main JAR file containing META-INF/plugin.xml
descriptor with tag (or if not specified).
Okay. Locate it and do what exactly?
My solution was to copy the template for a gradle IntelliJ plugin and copy this example which led me to declare the dependency by plugin name with no version, groupId. In my case I wanted to use classes from the built-in maven plugin so I added this to the plugins = [....]. The plugin will automatically grab the version of that plugin that is in your IntelliJ.
build.gradle
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.26'
}
group 'com.whatever'
version '1.0-SNAPSHOT'
id 'MyPlugin'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime files('maven.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.2'
plugins = ['maven']
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}

How to add dependency sources to to IntelliJ

I have an IntelliJ project with a gradle build file that includes several projects from a maven central repository. One such dependency is Geb.
When I navigate my classes, I sometimes come across a Geb class that looks interesting. I select "Go to declaration" and get a sad "Cannot find declaration to go to".
Obviously this is because IntelliJ has not loaded the Geb source files. But how do I get it to do that without including Geb as a source in my project? I DO NOT want Geb to be compiled into my project from source because I'm already including it as a dependency in my gradle build file.
Adding it as a module dependency does not work. This is like adding more sources.
I suppose I can grab the repo and build the jars and then include those. Is that really necessary?
Adding the IDEA plugin to the gradle file doesn't work.
Relevant part of the gradle script:
apply plugin: 'groovy'
apply plugin: 'idea'
dependencies {
// need to depend on geb-spock
testCompile "org.gebish:geb-spock:0.13.1"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile "org.apache.commons:commons-lang3:3.4"
testCompile "io.github.bonigarcia:webdrivermanager:1.5.0"
testRuntime "org.seleniumhq.selenium:selenium-support:2.53.1"
}
idea {
module {
downloadJavadoc = true // defaults to false
downloadSources = true
}
}
This is a complete build script that downloads all the dependencies with sources:
apply plugin: 'java'
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true // defaults to false
downloadSources = true
}
}
repositories {
mavenCentral()
}
dependencies {
// need to depend on geb-spock
testCompile "org.gebish:geb-spock:0.13.1"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile "org.apache.commons:commons-lang3:3.4"
testCompile "io.github.bonigarcia:webdrivermanager:1.5.0"
testRuntime "org.seleniumhq.selenium:selenium-support:2.53.1"
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
The dependency shows in the list:
And I am able to browse the source code, you can see the comments are there:
One of the possible explanation might be that in your repository list is a repo, such as mavenLocal or a caching Artifactory, that doesn't have the sources dependency.
The ordering of the repositories matters, so if mavenLocal is first and the sources are not available there, I believe they will not get downloaded. A possible fix would be to remove the dependency from mavenLocal and re-download it, change order of dependencies or if it is the parent script, exempt your subproject when adding the repositories:
configure(allprojects - project(':my-subproj')) {
repositories {
...
}
}
I don't think there is any way you can prevent that from the subproject's build script though. It must be done in the parent.

Gradle dependencies in Idea project

I'm trying to use Gradle, but Idea dont see dependices. Here is my build.gradle
group 'me.ozka'
version '1.0.1'
buildscript {
ext.kotlin_version = '1.0.3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.20'
compile 'org.eclipse.jetty:jetty-server:9.0.0.RC2'
compile 'org.eclipse.jetty:jetty-servlet:9.0.0.RC2'
}
When i'm trying import import org.eclipse.jetty.server.Server; Idea signal me an error. What i'm doing wrong?
upd: i'm also don't see jar files in Idea External library folder.
upd2: i'm add to build file apply plugin: 'jetty' and it's solve my problem!
You need to refresh your gradle dependencies.
Here are some ways of doing this.
Approach 1 (GUI):
Go to View -> Tool Windows -> Gradle
Click on the big refresh button (Refresh all gradle projects).
Approach 2 (Command):
gradle build --refresh-dependencies

IDEA showing a project twice in tree

I have a Kotlin project with Gradle that has two children. Whenever I try to open it in IDEA, one of the children is shown twice in the tree.
In the tree, you can see two projects at top level, grpc and grp. The issue is that grpc (from top level) is the same project as the grpc that's a children of grp.
Here are my Gradle build files:
The parent gradle.build:
buildscript {
ext.kotlin_version = '1.0.1'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
The gradle.settings file:
include ':grpstd', ':grpc'
The grpc gradle.build:
apply plugin: 'antlr'
apply plugin: 'application'
apply plugin: 'kotlin'
mainClassName = 'sron.grpc.MainKt'
compileKotlin.dependsOn generateGrammarSource
generateGrammarSource {
arguments += ['-package', 'sron.grpc.compiler.internal']
}
dependencies {
antlr 'org.antlr:antlr4:4.5.2-1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.ow2.asm:asm:5.0.4'
compile project(':grpstd')
testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
The grpstd gradle.build:
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
Why is that project being shown twice? How can I prevent it?
Open your project structure dialog (you can use Ctrl+Alt+Shift+S), turn to the Modules section, check if you have duplicated module defined there.
If there is, remove the unnecessary ones.
You may want to try disabling the Create separate module per source set option when importing the Gradle module.
So, the full steps are:
Open Modules
Remove the gradle module
Re-import the module. On the second page of the import wizard make sure you disable the option: Create separate module per source set

How to run build.gradle with Sikuli integrated into the project?

I am using Sikuli in my project to handle some flash buttons. It's working fine while running scripts locally. The issue is that when I need to run the build.gradle, I need to have the Sikuli dependency in build.gradle. That is how I have written build.gradle. When I run the build, I get this error:
What went wrong: Could not resolve all dependencies for configuration ':compile'.
Could not find com.googlecode.javacpp:javacpp:0.1. Required by:
:new_qa_automation:1.0 > org.sikuli:sikuli-api:1.0.2 > org.sikuli:sikuli-c ore:1.0.1
Could not find com.googlecode.javacv:javacv:0.1. Required by:
:new_qa_automation:1.0 > org.sikuli:sikuli-api:1.0.2 > org.sikuli:sikuli-c ore:1.0.1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED.
Here is my build.gradle file
apply plugin: 'java' version = '1.0' apply plugin: 'project-report'
repositories { mavenCentral() maven { url
"http://repo.springsource.org/release" url
"http://oss.sonatype.org/content/groups/public/" } }
sourceCompatibility = 1.6 targetCompatibility = 1.6
configurations { cucumberRuntime { extendsFrom testRuntime } }
task test(overwrite: true) {
dependsOn assemble, processTestResources, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
//some args
systemProperties System.properties
}
} }
dependencies { compile 'org.seleniumhq.selenium:selenium-java:2.32.+'
compile 'org.apache.commons:commons-lang3:3.1' compile
'org.springframework:spring-context:3.2.3.RELEASE'
compile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+' compile group: 'commons-collections', name: 'commons-collections',
version: '3.+'
testCompile 'info.cukes:cucumber-java:1.1.2'
testCompile 'info.cukes:cucumber-spring:1.1.2'
testCompile 'info.cukes:cucumber-junit:1.1.2'
testCompile 'junit:junit:4.11' testCompile 'org.easytesting:fest-assert-core:2.0+'
}
Edit:
I added the URL for the Maven repositry. Now the error has changed to
ePage.java:9: error: package org.sikuli.script does not exist
import org.sikuli.script.FindFailed;
sikuli-script.jar in Sikuli IDE project not provide in any repository so you must use it like a 3rd party jar
see:
"Mavan's central repository will not answer on any Sikuli stuff" https://answers.launchpad.net/sikuli/+question/185713
"Gradle: Make a 3rd party jar available to local gradle repository" Gradle: Make a 3rd party jar available to local gradle repository
The Sikuli code base appears to be fragmented. It's quite confusing; I know of 3 different sets of Java bindings. (one, two, three)
I think the one you're pulling with Maven is this: http://code.google.com/p/sikuli-api/
If so, org.sikuli.script is not the right import. You don't include your code to show me what you're trying to do with Sikuli, but most of the things you'd want to import are somewhere under org.sikuli.api.
Just download the sikulix jar and mention it in build.gradle
eg: compile files('C:\Users\vedavyasa\Documents\jar\sikulixapi.jar')