Gradle publishing - add testCompile dependencies to ivy.xml - gradle

When I have the publishing section below in my build.gradle I'll get my ivy.xml descriptor file filled with dependencies as desired. So far so good.
Question: How can I archive it so that the publishing task will also add the testCompile dependencies from my build.gradle dependency section to my ivy.xml file?
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier "source"
}
publishing {
publications {
jarAndSources(IvyPublication) {
from components.java
artifact(sourceJar) {
type "source"
extension "src.jar"
}
}
}
repositories {...}
}
Do I need to specify some sort of a configuration?

Related

Downloading the source jars for dependencies into a directory with Gradle 7

I am copying dependencies as JARs into the folder "jars" like so
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
}
task copyToLib(type: Copy) {
into "jars"
from configurations.runtimeClasspath
}
build.dependsOn(copyToLib)
How can I also include each dependencies' source in the same folder?

Maven - Publishing Multiple Sub-Modules/Artifacts

I have a Kotlin project organised like so:
project-name
> project-name-core
> project-name-domain
My gradle publishing script is set up like this:
publishing {
repositories {
mavenLocal()
}
publications.all {
pom.withXml(configureMavenCentralMetadata)
}
publications {
mavenPublication(MavenPublication) {
from components.java
groupId 'com.project'
artifactId 'project-name'
artifact sourcesJar
artifact javadocJar
}
}
}
When I run ./gradlew publishToMavenLocal I can see project-name in the local repository cache, but not project-name-core or project-name-domain.
How do I configure gradle to publish my sub-modules to the maven local repository cache?
Best guess is that you only applied the publishing plugin to the root project and not the subprojects.
If you intend to publish the root project (src/) in addition to the subprojects, then you should move the configurations to the allprojects block:
allprojects {
publishing {
publications.all {
pom.withXml(configureMavenCentralMetadata)
}
publications {
mavenPublication(MavenPublication) {
from components.java
groupId 'com.project'
artifactId 'project-name'
artifact sourcesJar
artifact javadocJar
}
}
}
}
Otherwise if you only want to publish the subprojects, then replace allprojects with subprojects
Also, you don't need to add configure the repositories with mavenLocal().

gradle subProject configuration dependencies not being add to war

I have a main project that depends on 2 subProjects. All 3 projects have a custom configuration called server.
When I have the following war task, only the dependencies in the main project configuration.server are being added to the war.
task fatWar(type: War) {
archiveName = "arms-fat.war"
classpath configurations.server
classpath configurations.compile
}
How do I add the subProject server configuration dependencies to the war?
EDIT:
Here are some snippets of my build files for context.
rootProject build.gradle
configurations {
server
}
dependencies {
server 'org.glassfish.jersey.media:jersey-media-multipart:2.22.2'
...
}
task fatWar(type: War) {
archiveName = "arms-fat.war"
classpath configurations.server
classpath configurations.compile
}
subProject build.gradle
configurations {
server
}
dependencies {
server 'mysql:mysql-connector-java:5.1.38'
...
}
When I run the fatWar task, the mysql-connector.jar, among others are not bundled in the war
Actually, "classpath" is a property, not a method, so replace the two assignments with a single one, whose value is "configurations.server + configurations.compile".
I was able to solve this (thanks to the link David provided) with the following:
subprojects.each { subproject -> evaluationDependsOn( subproject.path ) }
task fatWar(type: War) {
archiveName = "arms-fims-fat.war"
subprojects.each { subproject ->
project.configurations.server.dependencies.addAll(subproject.configurations.server.dependencies)
}
classpath configurations.server
classpath configurations.compile
}

build.gradle to pom.xml conversion

I have following code in build.gradle:
task javadocJar(type: Jar, dependsOn: 'javadoc') {
from javadoc.destinationDir
classifier = 'javadoc'
}
task sourceJar(type: Jar, dependsOn: 'classes') {
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts {
archives javadocJar
archives sourceJar
}
When I try building pom.xml it only includes the dependencies in it. I want to generate a pom.xml which can execute all these tasks automatically when i do mvn install. These tasks are already defined by maven as it goals. How can I achieve this?

build.gradle - error deploying artifact

I'm having issues with publishing to local nexus maven repository.
I admit, I don't have much experience with using gradle.
I will say that I have tried understanding the documentation and examples that are given through the gradle website (along with a few stackoverflow questions).
I am getting the following error when I try to publish:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Failed to publish publication 'maven' to repository 'maven'
> Error deploying artifact 'com.myproject:myproject-sdk:jar': Error deploying artifact: Resource to deploy not found: File: http://git.site.com:8081/nexus/content/repositories/releases/com/myproject/myproject-sdk/3.0.0/myproject-sdk-3.0.0.jar does not exist
the entire build.gradle file looks like this:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'build-version'
buildscript {
repositories {
maven { url "http://git.site.com:8081/nexus/content/groups/public" }
maven { url 'https://geonet.artifactoryonline.com/geonet/public-releases' }
mavenCentral()
}
dependencies {
classpath 'nz.org.geonet:gradle-build-version-plugin:1.+'
}
}
repositories {
maven {
url "http://git.site.com:8081/nexus/content/groups/public"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.code.gson:gson:2.2.4'
compile 'commons-codec:commons-codec:1.9'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
maven(MavenPublication) {
artifactId = 'myproject-sdk'
groupId = 'com.myproject'
version '3.0.0'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
repositories {
maven {
// nexus maven credentials
credentials {
username "MY_USERNAME"
password ""MY_PASSWORD"
}
if(version.endsWith('-SNAPSHOT')) {
url "http://git.site.com:8081/nexus/content/repositories/snapshots"
} else {
url "http://git.site.com:8081/nexus/content/repositories/releases"
}
}
}
}
I am using Android Studio and this project is a Java project.
I don't understand the message because it says "Resource to deploy not found" and it points to a url at nexus.
I would expect a message like "Resource to deploy not found: File: c:/directory_that_doesn't_exist/whatever.jar"
Additional Information -
The gradle tasks listed under 'All tasks' are:
assemble
build
buildDependents
buildNeeded
check
classes
clean
compileJava
compileTestJava
generatePomFileForMavenPublication
jar
javadoc
processResources
processTestResources
publish
publishMavenPublicationToMavenLocal
publishMavenPublicationToMavenRepository
publishToMavenLocal
sourceJar
test
testClasses

Resources