I have locally deployed the nexus repository for maven-snapshots. I has a spring boot application (java).
I need to publish some projects to this repository, and then connect these libraries to other projects using the nexus repository.
- gradle version
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.2 (Oracle Corporation 17.0.2 8-86)
- published artifact
gradle.buid
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
id 'java'
}
group = 'com.model'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven {
url "http://localhost:8081/repository/model-snapshot/"
setAllowInsecureProtocol(true);
}
}
ext {
springJacksonVersion = "2.13.4"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.fasterxml.jackson.core:jackson-annotations:' springJacksonVersion
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
}
publishing {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/repository/model-snapshot/") {
authentication(userName: "user", password: "1")
setAllowInsecureProtocol(true);
}
pom.version = "1.0-SNAPSHOT"
pom.artifactId = "m-entities"
pom.groupId = "com.model"
}
}
}
- Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':m-entities'. .... Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method publishing() for arguments [build_7pz2gcbsao2wyri8rdvmjwrzm$_run_closure5@482a5d97] on project ':m-entities' of type org.gradle.api.Project. at org.gradle.internal.metaobject.AbstractDynamicObject$CustomMissingMethodExecutionFailed.(AbstractDynamicObject.java:190) at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:184) at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.methodMissingException(BasicScript.java:162) at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:167) at org.gradle.groovy.scripts.BasicScript.invokeMethod(BasicScript.java:84) at build_7pz2gcbsao2wyri8rdvmjwrzm.run
- the project in which the library is connected, which should be published in the nexus repository
gradle.build
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'com.model'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven {
name 'm-shapshot'
url "http://localhost:8081/repository/model-snapshot/"
setAllowInsecureProtocol(true)
credentials {
username project.repoUser
password project.repoPassword
}}
}
ext {
set('springCloudVersion', "2021.0.4")
set('testcontainersVersion', "1.17.4")
mapStructVersion = '1.5.3.Final'
mEntitiesVersion = '0.0.1-SNAPSHOT'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.model:m-entities:0.0.1-SNAPSHOT'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:postgresql'
}
dependencyManagement {
imports {
mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
- gradle.properties
repoUser=user
repoPassword=1
Could not GET 'http://localhost:8081/repository/model-snapshot/com/model/m-entities/0.0.1-SNAPSHOT/maven-metadata.xml'. Received status code 401 from server: Unauthorized Disable Gradle 'offline mode' and sync project
Does anyone have any ideas on how to configure uploading artifacts to the local nexus repository and using this repository to get the artifacts published there ?
CodePudding user response:
in the publishing project - can you try below
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.model'
artifactId = 'm-entities'
version = '1.0-SNAPSHOT'
from components.java
}
}
}
publishing {
repositories {
maven(url: "http://localhost:8081/repository/model-snapshot/") {
authentication(userName: "user", password: "1")
setAllowInsecureProtocol(true);
}
}
}
CodePudding user response:
It works for me:
plugins {
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'java-library'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
ext {
springJacksonVersion = "2.13.4"
nameSnapshotRepo = 'repo-shapshot'
urlPSnapshotRepo = 'http://localhost:8081/repository/repo-snapshot/'
artefact = 'your-starter' /*like title of name project catalog*/
}
repositories {
mavenCentral()
maven {
name "${nameSnapshotRepo}"
url "${urlSnapshotRepo}"
setAllowInsecureProtocol(true)
credentials {
username 'admin'
password 'admin'
}
}
During the build, a warning will appear, how to remove it, I do not know. But this code allows you to publish artifacts to Nexus, which works over HTTP.