I have Intellij Idea 2016.1 gradle-application(Not Android) written in Kotlin. I need to place it in jCenter and add to the Android-application as a dependency. I can not find any information about it. All references refer to the Android project. I have no concept of how this can be done. Looking for detailed instructions
Publishing Kotlin libraries to jCenter is absolutely the same as for JAva libraries.
buildscript {
ext.kotlinVersion = '1.0.2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
plugins {
id "com.jfrog.bintray" version "1.6"
}
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
group '<groupId>'
version '<version>'
sourceCompatibility = 1.6
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
bintray {
user = '<bintray user name>'
key = '<bintray API key>'
publications = ['mavenJava']
pkg {
repo = '<repository name on bintray>'
name = '<artifactId>'
version {
name = project.version
released = new Date()
vcsTag = "v${project.version}"
}
}
}
task sourcesJar(type: Jar, dependsOn: project.classes) {
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: project.javadoc) {
from javadoc.destinationDir
}
artifacts {
archives sourcesJar, javadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId project.bintray.pkg.name
from components.java
artifact sourcesJar {
classifier = 'sources'
}
artifact javadocJar {
classifier = 'javadoc'
}
}
}
}
Create a repository on bintray and then just call ./gradlew bintrayUpload. If you don't ask the bintray plugin to publish an uploaded dependency then you have to publish it manually from your bintray account.
When the dependency is published you can link it to jCenter from your account. After it's published on jCenter you can use it as a regular dependency from an Android project.
Michael's answer is correct. But if you execute bintrayUpload, the kotlin dependency will be included to the .pom file. This lead to adding kotlin libs twice when you include your lib in gradle-project. This lead to DuplicateFileException. I don't know what's wrong. Maybe I did some stupid mistake. But if this is your case to, you can execute gradlew build with Michael's build.gradle for generating .jar and source.jar. Then you can create your own .pom file with no dependencies and deploy 3 files(jar, source.jar and .pom) to bintray manually. Then link library to jCenter.
For example:
Generated .pom with ./gradlew bintrayUpload:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.livemaster</groupId>
<artifactId>LongToWords</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.0.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Your own .pom for deploying without kotlin-dependencies:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.livemaster</groupId>
<artifactId>LongToWords</artifactId>
<version>0.1</version>
</project>
Related
After updating the cucumber version to 7.2.3, Allure not generating reports. (unknown report and NaN%). It still uses the config file in the directory. I think it's not about the folder path. If I decrease the version to 5.6.0 it is working.
The related part of the pom.xml is like below.
Does anyone have a solution for this??
Thanks,
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.2.3</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>2.17.3</version>
</dependency>
<dependencies>
<argLine>
-Dcucumber.options="--plugin io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm
</argLine>
I know that it doesn't answer the exact question but hope it can help somebody.
I had the same issue with Gradle - build/allure-results folder had only one small json file that generated empty allure report.
It seems like not all the Cucumber and Allure versions are compatible with each other. So I have found a compatible versions pair of Cucumber and Allure. Surprisingly they are the same as author has:
cucumberVersion = '7.2.3'
allureVersion = '2.17.3'
related part of my build.gradle:
plugins {
id 'java'
id 'io.qameta.allure' version '2.9.1'
}
apply plugin: 'io.qameta.allure'
dependencies {
implementation group: 'io.cucumber', name: 'cucumber-java', version: '7.2.3'
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '7.2.3'
implementation group: 'io.qameta.allure', name: 'allure-cucumber7-jvm', version: '2.17.3'
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'html:results.html',
'--plugin', 'pretty',
'--plugin', 'io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm',
'--glue', 'step_definitions',
'src/test/resources']
}
}
}
No, no this problem is not depend any cucumber version. Allure report have to write allure-result to any folder on test executing so you can use this commandline under <argLine> raw your pom.xml.
<systemPropertyVariables>
<allure.results.directory>
${project.build.directory}/allure-results
</allure.results.directory>
</systemPropertyVariables>
I'm developing a IDEA-Plugin. But after updating Intellij IDEA, the ide always show the warning that leading to the failure of code completion:
Cannot access class 'com.intellij.psi.PsiElement'. Check your module classpath for missing or conflicting dependencies
I have tried to upgrade gradle plugin or dependencies version, unfortunately it not work.
My build.gradle script at root project directory:
plugins {
id 'org.jetbrains.intellij' version '1.1.6'
id "org.jetbrains.kotlin.jvm" version '1.5.21'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}
intellij {
version '2021.2'
plugins = ['java','Kotlin']
}
patchPluginXml {
changeNotes.set(
"""
Add change notes here.<br>
<em>most HTML tags may be used</em>
"""
)
}
test {
useJUnitPlatform()
}
My plugin.xml file:
<idea-plugin>
<id>org.example.TestPlugin</id>
<name>Plugin display name here</name>
<vendor email="support#yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.kotlin</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
<actions>
<!-- Add your actions here -->
<action id="TestAction" class="org.example.TestAction" text="TestAction" description="TestAction">
<add-to-group group-id="GenerateGroup" anchor="last"/>
</action>
</actions>
</idea-plugin>
What's wrong with my Project? Thanks for your answer!
Since the IntelliJ SDK 2020.3, you're supposed to use Java 11, not 8.
Ref: https://blog.jetbrains.com/platform/2020/09/intellij-project-migrates-to-java-11/
Error:(11, 40) Kotlin: Cannot access built-in declaration
'kotlin.coroutines.SuspendFunction1'. Ensure that you have a
dependency on the Kotlin standard library
fun Route.coroutineHandler(fn: suspend (RoutingContext) -> Unit) {
handler { ctx ->
launch(ctx.vertx().dispatcher()) {
try {
fn(ctx)
} catch (e: Exception) {
ctx.fail(e)
}
}
}
Like Slaw commented just add the kotlinx-coroutines-core dependency to your project as described in the README
Maven
Add dependencies (you can also add other modules that you need):
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.3.5</version>
</dependency>
And make sure that you use the latest Kotlin version:
<properties>
<kotlin.version>1.3.70</kotlin.version>
</properties>
Gradle
Add dependencies (you can also add other modules that you need):
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
}
And make sure that you use the latest Kotlin version:
buildscript {
ext.kotlin_version = '1.3.70'
}
Make sure that you have either jcenter() or mavenCentral() in the list of repositories:
repository {
jcenter()
}
I am using javax.mail library in my project. My project is building fine using - mvn clean install, but when i try to debug my Intellij IDE shows error and it is not able to recognize the javax.mail imports. I have restarted my IDE from FILE -> Invalidate Caches and restart,still no luck.
These are not getting recognized by intellij IDEA,stating unused imports. I am using below the depeendency versions as:- javax.activation - 1.1.1 and javax.mail - 1.4.
Because the project is building fine,i believe the problem lies in some IDE setting.Kindly let me know if this can be resolved.
Try this maven dependency:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope> <!-- add this only if code will run in a java container (i.e. tomcat, etc)-->
</dependency>
And you should also see the mail classes under External Libraries -> Maven:javax.mail:mail:1.4 -> mail-1.4.jar -> javax.mail
There are also newer versions of the java mail dependency you can use, like 1.4.7 or 1.5.0-b01
The latest version (as pointed out by #Mark Rotteveel) is 1.6.3 and the maven coordinates have changed to jakarta:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.3</version>
</dependency>
Based on your code I have created a simplified project version with only two files; pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>message-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
</dependencies>
</project>
and SendMail.java
package com.test;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Properties;
public class SendMail {
public static void main(String[] args) {
sendMail(new Exception("Problem with cable"));
}
public static void sendMail(Exception exception) {
String to = "destination#test.com";
String from = "sender#test.com";
String host = "smtp.test.com";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Trade-processor instance shutdown!");
message.setText(getExceptionMessage(exception));
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
private static String getExceptionMessage(Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}
Make sure your 'java' source folder is marked as source (right click on it and select 'Mark directory as -> sources root' if it is not already light blue)
Make sure the class package (com.test) names match i.e. 'src/main/java/com/test/SendMail' on the project pane and 'package com.test' in SendMail.java
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.