gradle publishing multi module project to AWS Artifact only publishes META-INF - scala

I recently started using gradle and trying to publish a multi module project to AWS Artifact. My build file for submodules looks like below
Module: core
buildscript {
dependencies {
classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:0.4.34"
}
}
plugins {
id "net.researchgate.release" version "2.8.0"
}
group "com.local"
apply plugin: "java"
apply plugin: "jsonschema2pojo"
apply plugin: "maven"
apply plugin: "net.researchgate.release"
jar {
baseName "core-schema"
}
release {
tagTemplate = 'core-${version}'
}
jsonSchema2Pojo {
source files("${projectDir}/src/main/resources/json")
generateBuilders = true
}
dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'javax.validation:validation-api:2.0.0.Final'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
}
afterReleaseBuild.dependsOn uploadArchives
spark-example
plugins {
id 'java'
id 'java-library'
id 'scala'
id 'com.github.johnrengelman.shadow' version '1.2.4'
}
apply plugin: 'scalaStyle'
scalaStyle {
configLocation = "${project.rootDir}/scalastyle_config.xml"
includeTestSourceDirectory = true
source = "src/main/scala"
testSource = "src/test/scala"
}
dependencies {
compile group: 'org.apache.spark', name: "spark-core_2.11", version: '2.4.2'
compile group: 'org.apache.spark', name: "spark-sql_2.11", version: '2.4.2'
}
configurations {
runtime.exclude module: 'spark-core_2.11'
runtime.exclude module: 'spark-sql_2.11'
}
compileScala.dependsOn(scalaStyle)
jar {
mainClassName = 'NONE'
baseName "spark-sample"
}
tasks.withType(ScalaCompile) {
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
}
tasks.withType(ScalaCompile) {
configure(scalaCompileOptions.forkOptions) {
memoryMaximumSize = '1g'
jvmArgs = ['-XX:MaxPermSize=512m']
}
}
And main application build file looks like below:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
now when I run gradle build I can see jars getting created for all the modules and root project under corresponding build/libs/ directory with code files. However when I do gradle publish I only see root jar getting published with only MANIFEST.NF file as shown below:
Update:
As suggested by #nico I have tried adding the publishing block in allprojects{} block but it is publishing each project with the root project name and overriding all of them as seen in below log. I have also tried adding the publishing block in subproject like mentioned in this post but still same output.
2030009268:spark-store user$ gradle publishAllPublicationsToMavenRepository
> Task :core:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
> Task :spark-sample:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
Updated root project build:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
allprojects {
apply plugin: 'maven-publish'
apply plugin: 'java-library'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
}

Regarding your main application build file:
Try including the publishing{} block inside of an allprojects{} block or add it to the above subprojects{} block as well. Currently the publishing-specification is only applied on root-project level.

Related

gradle multiproject fails when implement another subproject

I am recently learning gradle and I tried to build multi project module.
The project structure is like
.
├─ build.gradle.kts
├─ settings.gradle.kts
├─ sub1
│ └── build.gradle.kts
│ └── src
├─ sub2
│ └── build.gradle.kts
│ └── src
sub1 is first subproject and sub2 is second subproject.
sub1 project is built in kotlin with spring-starter-jpa
sub2 project is build in scala with spark
What I need now is implement sub1 project from sub2 and use a Map. All the logic sub1 has is to create that Map, so other sub projects can implement and use it. In above example there is no sub3 but in my real project there is several other sub projects which are built in kotlin and use spring-starter-jpa as well. At those sub projects implement sub1 works fine but it only fails to build with sub2. Followings are gradle.build.kts for each project.
build.gradle.kts
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.org.datlowe.maven-publish-auth:buildSrc:2.0.2")
classpath("com.github.jengelman.gradle.plugins:shadow:5.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.properties["kotlinVersion"]}")
}
}
allprojects {
repositories {
maven {
name = "osgeo-release"
url = uri("https://repo.osgeo.org/repository/release")
}
maven {
name = "hortonworks"
url = uri("https://repo.hortonworks.com/content/repositories/releases")
}
mavenLocal()
mavenCentral()
}
configurations {
all {
exclude(module = "spring-boot-starter-logging")
}
}
apply(plugin = "org.jetbrains.kotlin.jvm")
group = "example"
version = "0"
}
subprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
sub1/build.gradle.kts
plugins {
id("org.jetbrains.kotlin.plugin.spring") //version is handled at setting.gradle.kts not important
id("org.jetbrains.kotlin.plugin.jpa")
id("org.springframework.boot")
id("io.spring.dependency-management")
id("org.jlleitschuh.gradle.ktlint")
}
dependencies {
// kotlin
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-noarg")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("javax.persistence:javax.persistence-api")
runtimeOnly("mysql:mysql-connector-java")
}
sub2/build.gradle.kts
plugins {
id("com.github.johnrengelman.shadow")
id("application")
id("scala")
id("com.github.maiflai.scalatest")
}
dependencies {
implementation(project(":sub1"))
implementation("org.scala-lang:scala-library:2.12.11")
testImplementation("org.scalatest:scalatest_2.12:3.2.3")
testImplementation("org.scalatestplus:junit-4-13_2.12:3.2.3.0")
testRuntimeOnly("com.vladsch.flexmark:flexmark-all:0.35.10")
}
application {
mainClass.set("my.application.path")
}
tasks.withType<ScalaCompile>().configureEach {
scalaCompileOptions.additionalParameters = listOf("-feature")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
When I build sub2 it thorws
Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
Required by:
project :sub1
Can you guys please help me?
Thx in advance
I don't know why, but if I add all the implementation and plugin and repository related to sub1 at sub2 does solve this problem.

How can I use the full ksqldb client api with gradle?

How can I use the full ksqldb client api with gradle? Why are there 2 different packages?
repositories {
mavenCentral()
jcenter()
maven {
url "https://packages.confluent.io/maven/"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
compile group: 'io.confluent.ksql', name: 'ksqldb-api-client', version: '6.0.0'
}
I would like to reference v0.11.0. It contains more methods:
https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-clients/java-client/api/io/confluent/ksql/api/client/Client.html
https://docs.ksqldb.io/en/0.10.0-ksqldb/developer-guide/ksqldb-clients/java-client/api/io/confluent/ksql/api/client/Client.html
import io.confluent.ksql.api.client.ClientOptions
import io.confluent.ksql.api.client.*
fun main()
{
val KSQLDB_SERVER_HOST = "localhost"
val KSQLDB_SERVER_HOST_PORT = 8089
val clientOptions = ClientOptions.create()
.setHost(KSQLDB_SERVER_HOST)
.setPort(KSQLDB_SERVER_HOST_PORT)
val client: Client = io.confluent.ksql.api.client.Client.create(clientOptions)
val topics = client.listTopics() //not available in 6.0.0
}
Edit:
Based on #Hellmar Becker's post I would like to use the standalone (community) version not the commercial Confluent Platform version. It looks like that the CP version uses an older API version anyway.
I found an example how to do this with pom.xml on Github developer guide, but I would like to use a build.gradle file
There are different numbering schemes for the community licensed KSQLDB (currently v0.12) and the commercial Confluent Platform (currently v6.0.1). Maybe this comparison helps: https://docs.confluent.io/platform/current/ksqldb/index.html#ksqldb-standalone-and-ksqldb-for-cp.
I managed to convert the pom.xml to gradle.build file from the developers guide in the following manner:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.4.21'
}
version '1.0-SNAPSHOT'
repositories {
jcenter()
maven() {
url "https://ksqldb-maven.s3.amazonaws.com/maven/"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "io.confluent.ksql:ksqldb-api-client:0.11.0"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

emacs debugging and setting breakpoints in java code built with gradle

GNU Emacs 24.3.1
Gradle 2.2
Hello,
I am using emacs for writing java applications. I have created some java library and building using gradle and testing with spockframework where I have all my test cases.
However, now I want to debug my java code using emacs. However, I haven't found any way of doing this. I would like to set a breakpoint and step through my java code.
Here is my gradle build file:
apply plugin: 'java'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.igniterealtime.smack:smack-core:4.1.0'
compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'org.codehaus.groovy:groovy:2.3.6'
}
jar {
baseName = 'SunSmackClient'
version = '1.0.0'
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
Example of my spockframework using test:
public class SmackClientSpec extends Specification {
private SmackClient smackClient;
/* Test 1 */
#IgnoreRest
def 'Create a connection to XMPP server'() {
setup: /* Setup connection object */
def domain = 'domain'
def username = 'username'
def password = 'password'
SmackClient smackClient = new SmackClient()
expect: /* Connection to return true */
smackClient.createConnection(domain, username, password) == true
}
}
Many thanks in advance

Gradle artifactory plugin * How does one specify the artifact to be sent to Artifactory

I am building an android apk: app/build/outputs/apk/app-debug.apk and would like to have it uploaded to Artifactory.
The build.gradle (see below) generates an entry in my local Artifactory when invoked with: gradlew artifactoryPublish, but, the apk file is not uploaded.
Would someone be so kind as to show me what to add to this script so that the file named above is sent over to Artifactory. Thank you.
Here is build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
plugins {
id "com.jfrog.artifactory" version "3.0.1"
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply plugin: 'java'
artifactory {
contextUrl = 'http://localhost:8081/artifactory'
publish {
repository {
repoKey = 'libs-releases-local'
username = 'admin' //The publisher user name
password = 'password' //The publisher password
maven = true
}
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact(file('app/build/outputs/apk/app-debug.apk'))
}
}
}

Gradle: illegal repetition error

just started to use artifactory so as to manage all the libraries that i use..therefore i had to have the artifactory plugin. I used the screencast tutorial at http://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin and added the buildScript as follows to download the plugin..
buildscript {
repositories {
maven { url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath (
group: 'org.jfrog.buildinfo', name:
'build-info-extractor-gradle', version: '2.1.0'
)
}
}
then in gradle.properties file in my gradleUserHomeDir, i have the following, the password is encrypted by artifactory.
artifactory_user=admin
artifactory_password={DESede}ifW8DYgu849GR8EnzUMOlj/L8cwy6FQfRZgHHTyj9L0=
artifactory_contextUrl=http://localhost:8081/artifactory
Then i ran gradle tasks. the plugin was downloaded yes, but something is going wrong. this is the output
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
FAILURE: Build failed with an exception.
Where:
Build file 'S:\src\JEE-Workspace\movieplex7\build.gradle' line: 47
What went wrong:
A problem occurred evaluating root project 'movieplex7'.
Illegal repetition
{DESede}ifW8DYgu849GR8EnzUMOlj/L8cwy6FQfRZgHHTyj9L0=
here is the build.gradle
buildscript {
repositories {
maven { url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath (
group: 'org.jfrog.buildinfo',
name: 'build-info-extractor-gradle', version: '2.1.0'
)
}
}
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'eclipse-wtp'
apply plugin: 'artifactory'
project.description = 'Java EE 7 Hands-on Lab'
version= '1.0'
group = 'org.glassfish.movieplex7'
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release' username = "${artifactory_user}"
password = "${artifactory_password}" maven = true
}
}
}
dependencies {
providedCompile 'javax:javaee-api:7.0'
//providedCompile 'org.glassfish.main.extras:glassfish-embedded-web:4.0'
}
it suddenly worked when i put each property in its own line like this
`repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true`