IntelliJ Idea 16 CE gradle issues - intellij-idea

In my gradle file I am trying to use the following to solve another issue. This is my gradle file:
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task copyDependenciesToTarget(type: Copy) {
println 'Copying dependencies to target...'
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
}
build.dependsOn(copyDependenciesToTarget)
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
The problem are is this:
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
When I run the application I get this Exception:
org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated cannot be cast to org.gradle.api.internal.file.copy.CopySpecInternal
Main problem is, I have no idea how to fix this error, I simply want my project to create a JAR file that works with JDBC, using this gradle code seems to be a solution for that issue, but now I have run into another problem, yet again.
Please let me know if you require any additional information and thank you in advance. Literally, I cant even. This problem.
EDIT
As stated in the comments. My project runs fine when I run it through the IDE. There is an issue when I create a JAR file using gradle. The bare gradle file that IntelliJ created when I started the gradle project follows (Added the jar config so my Main class would be picked up):
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
When I execute my app from terminal after the JAR has been created (keeping in mind there are no issues when hitting run in the IDE) with java -jar myAppName.jar:
java.lang.ClassNotFoundException: org.sqlite.JDBC
NOTE: Usually I get a full stack running a java app, but in this case the above is the only output.
I am using this JAR for my sqlite needs:
sqlite-jdbc-3.15.1
As a test I commented out the Sqlite usage in my application and the JAR file worked fine. My GUI was displayed and everything went as expected (all things considered). The JAR stops working when I add the sqlite JAR file usage (code). Added it the same as my other libs (like retrofit), so this seems to be quite a strange issue.
Please let me know if I have explained the issue correctly?

Related

Build Intellij plugin in IDEA 2019.1 & 2020.3

Building for IDEA 2019.1 works like a charm! I thought that building for 2020.3 would be just a matter of pointing to 2020.3 installation folder and that's it, but it is not being even close to it.
That's my gradle.build
group 'com.test.plugin'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
classpath group: 'org.jetbrains.intellij.plugins', name: 'gradle-intellij-plugin', version: '0.6.5'
}
}
apply plugin: 'java'
apply plugin: 'org.jetbrains.intellij'
intellij {
localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
}
sourceCompatibility = 1.8
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime group: 'com.google.guava', name: 'guava', version: '23.0'
runtime group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
}
It is important to mention that since I'm working behind a restricted company proxy I can't just set the Intellij version in order to get the necessary distribution files to the build (Intellij.localPath)
Building it on IDEA 2019.1, JDK 1.8 works fine. In order to build the same code for a IDEA 2020.3 I just replaced the Intellij distribution path:
intellij {
//localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
localPath 'C:/Dev/apps/ideaIU-2020.3'
}
Trying to build it now immediately throws it:
error: cannot access AnAction
bad class file: C:\Dev\apps\ideaIU-2020.3\lib\platform-api.jar(com/intellij/openapi/actionSystem/AnAction.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
What I understand form it is that AnAction class was built using Java 11. So, I replaced the project JDK to use also JDK11 and from that moment I started facing compilation errors, like com.intellij.psi.PsiJavaFile cannot be found.
I might be missing some conceptual point here.
it turns out there was a missing plugin dependency.
this line was not being effective to resolve such dependency. In order to fix that I had to remove apply plugin: 'java' and set intellij.plugin
intellij {
localPath 'C:/Dev/apps/ideaIU-2020.3'
plugin = ['com.intellij.java']
}

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>"""
}

io.micronaut.runtime.Micronaut - No embedded container found

I'm trying to build a Kotlin application but, even with successfully build, I face with the error bellow. What I'm doing wrong?
▶ java -jar build/libs/app-0.1.jar
22:10:02.122 [main] INFO io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application
Here is my build status:
▶ ./gradlew assemble
BUILD SUCCESSFUL in 3s
14 actionable tasks: 1 executed, 13 up-to-date
That is the part of my gradle.build file:
apply from: "dependencies.gradle"
apply from: "protobuf.gradle"
version "0.1"
group "app"
mainClassName = "app.Application"
dependencies {
compile "ch.qos.logback:logback-classic:1.2.3"
}
jar {
manifest {
attributes "Main-Class": mainClassName
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
I had a similar issue:
I was able to run code from IDE, but failed to run Docker container with the app
And had compile 'io.micronaut:micronaut-http-server-netty:1.1.0' in my build.gradle.
Also I was using shadowJar plugin and there was the issue. Adding:
shadowJar {
mergeServiceFiles()
}
solved the problem. It transforms entries in META-INF/services resources into a single resource. My shadowed jar file contained a lot of entries in this folder.
It is difficult to say for sure without seeing the project but one thing that could cause that issue would be not having a dependency on io.micronaut:micronaut-http-server-netty. A newly created app will have something like this in build.gradle...
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
compile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
compile "io.micronaut:micronaut-runtime"
compile "io.micronaut:micronaut-http-client"
// Make Sure You Have This...
compile "io.micronaut:micronaut-http-server-netty"
kapt "io.micronaut:micronaut-inject-java"
kapt "io.micronaut:micronaut-validation"
kaptTest "io.micronaut:micronaut-inject-java"
runtime "ch.qos.logback:logback-classic:1.2.3"
runtime "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.4.1"
testCompile "org.junit.jupiter:junit-jupiter-api:5.1.0"
testCompile "org.jetbrains.spek:spek-api:1.1.5"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:1.1.5"
}

How to debug xtend code in IntelliJ + Gradle?

I have just started to learn Xtend (http://xtend-lang.org/) and try to write a small app in IntelliJ 2016 based on a Gradle project using the Xtext/Xtend 2.10.0 plugins from the standard repository. The problem is that I cannot debug my Xtend code. Breakpoints are all ignored although debugging of Java code works. Debugging Xtend code only works if I use the IntelliJ wizard and create a standard IntelliJ project without using Gradle. I don't know how to fix this? Do I miss something? Does debugging works different in a Gradle project?
Here my Gradle file:
group 'GradleXtend'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
sourceCompatibility = 1.5
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.10.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:1.0.12'
}
}
xtend {
debugger {
//how to install debug info into generated Java code
//SMAP adds Xtend debug info on top of Java
//PRIMARY makes Xtend the only debug info (throws away Java line numbers)
//default is SMAP for Java projects and PRIMARY for Android
sourceInstaller = 'SMAP' //or 'PRIMARY' or 'NONE'
//whether to hide synthetic variables in the debugger
hideSyntheticVariables = false
}
}
My Xtend file:
package HelloWorld
class HelloWorld2 {
def static void main(String[] args) {
println("Hello")
}
}

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')