How to add plugin jar to the idea module classpath in gradle? - intellij-idea

I have a gradle build file and use the idea plugin to generate my project files.
import comp.BuildConfigurator
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'base'
apply plugin: 'comp-gradle-plugins'
assert gradle.gradleVersion == '1.0-milestone-7'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
test {
systemProperties = System.properties
}
idea.project {
javaVersion = "1.6"
downloadJavadoc = true
downloadSources = true
}
What I would like to is that we use some class from our internal plugin comp-gradle-plugins in the build file. When I open the build.gradle, Intellij Idea does not recognize the class comp.BuildConfigurator because it is not added to the classpath. How do I make the idea plugin to add the plugin jars to the module classpath?

Adding the plugin Jars to the module class path won't help. To make IntelliJ aware of Gradle's build script class path, you'll have to use the Gradle import in IntelliJ 13. However, I don't know if this will work with a Gradle version as old as 1.0-milestone-7.

Related

How to make idea plugin in gradle generate proper project configuration for Kotlin?

I have configured my build.gradle to run gradle test and gradle run properly. However, IDEA does not show any run/test tasks after importing the configuration generated by gradle idea. It seems that these tasks are not included at ipr/iws at all.
Here is my build.gradle:
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
}
}
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'application'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'idea'
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}
sourceSets {
test.kotlin.srcDirs += 'src/test/kotlin'
}
junitPlatform {
enableStandardTestTask true
}
defaultTasks 'run'
mainClassName = 'simpledb.server.Startup'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.2'
testRuntime (
'org.junit.jupiter:junit-jupiter-engine:5.0.2',
'org.junit.platform:junit-platform-launcher:1.0.2'
)
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
I was wondering is there any way to make generated project configurations include these tasks(run/test)? I have also heard people saying Don't use gradle idea, so is it impossible to use gradle idea to implement this?
It is simply not necessary in your case. Just open the build.gradle file with IDEA and everything should be smooth. The idea Gradle plugin is somewhat deprecated. Not officially, but it was created by Gradle team and is not actively developed to adapt to new IDEA versions and features and so on. So if you don't need special customizations, just open the build.gradle with IDEA and you should be good to go.

How to properly configure Kotlin plugin for Gradle?

I'm trying to build a basic Gradle project. My build.gradle file is below. I keep getting the below error. I don't get it because you can find the plugin here... where I think I'm directing to: https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
Update: same thing happens to the spring-boot plugin if I comment out the Kotlin line. It's not just specific to the Kotlin plugin.
The error:
Error:(21, 0) Plugin [id: 'kotlin', version: '1.1.1'] was not found in any of the following sources:
- Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/3.3/userguide/standard_plugins.html for available core plugins)
- Gradle Central Plugin Repository (no 'kotlin' plugin available - see https://plugins.gradle.org for available plugins)
Build.gradle:
buildscript {
ext.kotlin_version = '1.1.1'
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'java'
id 'kotlin' version "1.1.1"
id 'spring-boot'
}
group 'si.dime.kotlin.tutorials.rest'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile("org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE")
}
For non-core Gradle plugins (those that are not from the org.gradle namespace), you have to use a fully qualified id as well as a version number.
The official Kotlin documentation contains the id to use:
plugins {
id "org.jetbrains.kotlin.jvm" version "<version to use>"
}
(You can also find these ids by searching for the plugin on the plugins.gradle.org site.)

How to build my xtext language with gradle for android

I've written a test-DSL in xtext and generated an IntelliJ plugin.
I have a small Android-test project and in Android Studio my DSL-editor shows up and also generates the output files as expected.
Now I try to configure gradle to also generate the files, but this fails with an error.
I found the Android Integration section for the xtext-builder. This seems out-dated (e.g. it refers to org.xtext.android, which does not exist - also the link there is broken).
Anyway, in the xtext-gradle-plugin github repo there is an org.xtext.android.builder plugin: I guess this is the correct one.
My project build.gradle file looks like this (relevant parts only):
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/" // needed for org.xtext:xtext-android-gradle-plugin
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.xtext:xtext-android-gradle-plugin:1.0.14"
}
}
allprojects {
repositories {
jcenter()
mavenLocal() // This is required so that the mydsl language is found
}
}
when I activate the org.xtext.android.builder plugin in the build.gradle file of in my app module:
apply plugin: 'com.android.application'
apply plugin: "org.xtext.android.builder" // causes the Error!
I get this error:
Error:Unable to find method 'com.android.build.gradle.api.BaseVariant.getJavaCompiler()Lorg/gradle/api/tasks/compile/AbstractCompile;'...
I guess there's some version mismatch or something is not up-to-date.
Any ideas?
This was a bug (#73) in the xtext-gradle-plugin. It was fixed in Version 1.0.16.

Excluding files in a Gradle multi-project in Intellij

I have a simple multi-project gradle build file that I use as a base for an Intellij project, and I want to exclude some files from the build, so I use 'excludes' on the compile task (which I have just copy-pasted), as shown in the listing.
This seems to be working from the command line, but it doesn't work from within Intellij i.e. excluded files still get included in the compilation.
Any suggestions? (Gradle 2.10, Intellij 15.0.3)
subprojects {
apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
}
project(':projfoo') {
group = 'com.bshishani.projfoo'
}
project(':projbar') {
group = 'com.bshishani.projbar'
dependencies {
compile project(':projfoo')
testCompile project(':projfoo')
}
compileGroovy {
excludes = ['**/aaa.groovy', '**/bbb.groovy']
}
}
You can exclude directories programmatically from IntelliJ project by configuring the idea plugin:
For example:
idea {
module {
excludeDirs += [file("myproject/dir")]
}
}
I'm not sure how to exclude files (or globs) from compilation in IntelliJ. If this isn't possible, it may be preferable to move all of the "special" sources to their own directory.
More information about IntelliJ Module config with Gradle
To mark a folder in the source as excluded from the IDEA complier you must first right click a folder in the projects view.
Right click folder > Mark directory as > Excluded

spring-boot fails to load liquibase change on gradle build

I am using Spring-boot 1.1.1.RELEASE and I have an H2 database that is created at startup. When I run my main class from IntelliJ, all works well. When I run with "gradle build test" I get errors on my integration tests:
Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
at org.springframework.util.Assert.state(Assert.java:385)
at org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.checkChangelogExists(LiquibaseAutoConfiguration.java:80)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
Here is my gradle file:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
project.ext {
springBootVersion = '1.1.1.RELEASE'
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.1.RELEASE")
}
}
jar {
baseName = 'my-app'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/snapshot" }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot:1.0.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile("org.springframework:spring-orm:4.0.0.RC1")
compile("org.hibernate:hibernate-core:4.3.4.Final")
compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
compile("org.hibernate:hibernate-validator")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
compile("org.liquibase:liquibase-core")
testCompile('org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.spockframework:spock-spring:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.spockframework', module: 'spock-core'
exclude group: 'org.spockframework', module: 'spring-beans'
exclude group: 'org.spockframework', module: 'spring-test'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
I have in both src/main/resources and src/test/resources an application.properties file that contains the following entry:
liquibase.changeLog=classpath:db/changelog/db.changelog-master.xml
And then in both src/main/resources/db/changelog and src/test/resources/db/changelog I have a db.changelog-master.xml When I build the project, I see that build/resources/test and build/resources/main have the application.properties, db/changelog/db.changelog-master.xml there.
This would appear to be a classpath issue, since it works from within IntelliJ and not the commandline. Can anyone suggest what I might be doing wrong here?
I wanted to add my fix here (even though my build is Maven). My application.properties was in my root directory, but it would not find my db.changelog.xml classpath as directed from the root directory. It needed the classpath to be from my /resources directory. Maybe I have my application.properties in an unconventional location, but I thought it was to be put in the root directory.
My Fix
Though the actual path from my application.properties is this:
liquibase.change-log=classpath:/src/main/resources/liquibase/db.changelog.xml
It needed this path to find it:
liquibase.change-log=classpath:/liquibase/db.changelog.xml
I can see spock on the test classpath, so probably it's not using the right test context loader still (I wish they'd fix that). You need to add the loader or an initializer manually to your #ContextConfiguration. Docs here.