Cody
January 7, 2020, 9:03am
1
I asked the same question on stackoverflow, but did not receive a fully available answer.
In simple terms, I want the jar file I generated to include class files from other projects, while keeping third-party dependencies imported through the pom file as normal. Then publish it to the maven repository.
Looking forward to your help.
Cody
January 7, 2020, 9:15am
2
I have tried this:
configurations {
api.extendsFrom(internal)
}
dependencies {
internal project(':server-public')
implementation 'org.springframework:spring-web'
}
jar {
from { configurations.internal.collect { it.isDirectory() ? it : zipTree(it) } }
}
But there is still some problem, such as:
My internal project is still placed in the pom file.
Content from other projects does not appear in sources.jar and javadoc.jar.
Cody
January 10, 2020, 1:13am
3
After constantly trying, I wrote this configuration.
buildscript {
ext {
internalDependencies = [
project(':public'),
project(':server-public')
]
}
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
dependencies {
internalDependencies.each {
internal it
}
implementation 'org.springframework:spring-web'
}
jar {
from {
configurations.internal.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
from {
internalDependencies.collect {
it.sourceSets.main.allJava
}
}
archiveClassifier = 'sources'
}
javadoc {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
source internalDependencies.collect { it.sourceSets.main.allJava }
classpath += files(internalDependencies.collect { it.sourceSets.main.compileClasspath })
}
task javadocJar(type: Jar) {
from javadoc
archiveClassifier = 'javadoc'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = 'Server Client Library'
}
pom.withXml {
Node pomNode = asNode()
pomNode.dependencies.'*'.each {
Node temp = it
internalDependencies.each {
if (temp.groupId.text() == it.getGroup() && temp.artifactId.text() == it.getName()) {
temp.parent().remove(temp)
return false
}
}
}
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
This has basically met my needs. But itβs not elegant enough.
Is there a way to get projects through my custom configuration?
This will eliminates the need to list dependencies or even transitive dependencies through a list.