我有用Kotlin编写的Intellij Idea 2016.1 gradle-application(非Android)。我需要将它放在jCenter中并作为依赖项添加到Android应用程序中。我找不到任何有关它的信息。所有引用都涉及Android项目。我不知道如何做到这一点。寻找详细说明
答案 0 :(得分:3)
将Kotlin库发布到jCenter与JAva库完全相同。
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'
}
}
}
}
在bintray上创建一个存储库,然后只需调用./gradlew bintrayUpload
。如果您没有要求bintray插件发布上传的依赖项,那么您必须从您的bintray帐户手动发布它。
发布依赖关系后,您可以将其与您帐户中的jCenter
相关联。在jCenter
上发布后,您可以将其用作Android项目的常规依赖项。
答案 1 :(得分:1)
例如:
使用./gradlew bintrayUpload生成.pom:
<?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>
你自己的.pom用于部署没有kotlin依赖:
<?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>