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().
Related
I have a problem with resolving local dependency. I have a lib that I want to provide across my projects. So I've published it locally. The build.gradle looks like this:
...
plugins {
...
id("maven-publish")
...
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.wintermute.chatserver.core"
artifactId = "core"
version = "1.0"
from(components["java"])
}
}
}
In the other project, which is requiring the dependency I've added in the build.gradle this:
repositories {
mavenLocal()
mavenCentral()
}
But when I try to resolve the dependencies gradle complains about not resolvable dependency:
Could not resolve com.wintermute.chatserver.core:core:1.0.
Required by:
project :
It was successfull one time, then I've deleted the cache and since this it does not work anymore. Why is that? What I am doing wrong?
I am in a gradle 4.10 Spring Boot project called rest and in my build.gradle I have renamed the boot jar that is created by adding
bootJar.baseName = 'myprefix-rest'
When I run ./gradlew bootJar it creates a file called myprefix-rest-0.1.jar as expected.
However, when I add the maven-publish publish plugin and try to publish, it publishes the file called rest-0.1.jar
publishing {
publications {
bootJava(MavenPublication) {
artifact bootJar
}
}
repositories {
maven {
url = "$buildDir"
}
}
}
Why is it not picking up the baseName?
Why is it not picking up the baseName?
From the MavenPublication docs,
The default Maven POM identifying attributes are mapped as follows:
groupId - project.group
artifactId - project.name
version - project.version
so the actual file name of the boot jar file is not being used. You can overrride the artifactId,
publishing {
publications {
bootJava(MavenPublication) {
artifact bootJar
artifactId bootJar.baseName
}
}
..
}
I have a multi-project build with the following structure:
Root project 'just-another-root-project'
+--- Project ':producer'
\--- Project ':consumer'
The root settings.gradle file:
rootProject.name = 'just-another-root-project'
include 'consumer', 'producer'
...connects created modules.
The producer.gradle file:
plugins {
id 'java-library'
}
group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}
dependencies {
implementation 'com.sun:tools:1.7.0.13'
}
...has an external dependency (com.sun.tools) that is not published in Maven Central therefore I've added a link to the Nuiton repository.
The consumer.gradle file:
plugins {
id 'java'
}
group 'com.github.yarbshk.jarp'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
annotationProcessor project(':producer')
}
The build described above is not working! To make it so I was enforced to duplicate all repositories from producer.gradle into consumer.gradle. So the question is how to build the root project without the excessive dependency duplication? How to do it in the right way? Thanks for any answer or hint :)
UPDATE 1:
I get the following error when try to build the project with files shown above:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':consumer:compile'.
> Could not find com.sun:tools:1.7.0.13.
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.pom
https://repo.maven.apache.org/maven2/com/sun/tools/1.7.0.13/tools-1.7.0.13.jar
Required by:
project :consumer > project :producer
You can configure repositories directly in the root project like that:
root project build.gradle:
// configure repositories for all projects
allprojects {
repositories {
mavenCentral()
maven {
url 'http://maven.nuiton.org/release/'
}
}
}
EDIT (from you comment on other response)
You can also define only mavenCentral() repository on root project level (it will be added to repositories for all projects) and configure http://maven.nuiton.org/release repository only for producer subproject :
root project
repositories {
// will apply to all project
mavenCentral()
}
producer project
repositories {
maven {
url 'http://maven.nuiton.org/release/'
}
// mavenCentral inherited from root project
}
consumer project
// no need to re-define repositories here.
There is a section in an official gradle tutorial dedicated to this:
https://guides.gradle.org/creating-multi-project-builds/#configure_from_above
The root project can configure all projects:
allprojects {
repositories {
jcenter()
}
}
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?
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