How to publish the Jar file into jfrog as a new version instead of deleting/overwriting the pervious one - spring-boot

I am trying to publish the jar file into jfrog. At first it works fine. But when I tried to deploy an artifact under the same path more than once, changing the application version as 2.0.0(before it was 1.0.0), it gives me this error.
"message" : "Not enough permissions to delete/overwrite artifact 'customer-service:customer-service/com/customer/service/core/1.0.0/customer_ervice_core-1.0.0.jar' (user: 'username' needs DELETE permission)."
This is how my build.gradle file looks like.
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
repositories {
jcenter()
}
dependencies {
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
plugins {
id 'org.springframework.boot' version '2.7.5' apply false
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'maven-publish'
id 'com.jfrog.artifactory' version '4.28.1'
}
allprojects {
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'customer_service_core'
from components.java
pom {
name = 'Customer service core module'
description = 'Customer service core module'
}
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
jar {
enabled = true
}
publish {
repository {
repoKey = 'customer-service'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
// Reference to Gradle publications defined in the build script.
// This is how we tell the Artifactory Plugin which artifacts should be
// published to Artifactory.
publications('mavenJava')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
group = 'com.customer.service'
version = '2.0.0'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom SpringBootPlugin.BOM_COORDINATES
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// lombok dependencies
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
tasks.named('test') {
useJUnitPlatform()
}
I want to know is there any way to deploy our jar files as a new version without overwriting the pervious one? Do I always need to include a version number manually in the path to be deployed, if so how can I do it though this build.gradle file?

I think snapshot Repo maybe the solution and you can save many different versions as you like.
https://jfrog.com/knowledge-base/artifactory-how-does-the-max-unique-snapshots-parameter-work-in-artifactory/

Related

Gradle dependency resolution issue

I am converting a project from Maven to Gradle.
Here is my gradle.build file
plugins {
id 'java'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.5.30"
id "org.jetbrains.kotlin.plugin.spring" version "1.5.30"
id 'org.springframework.boot' version "2.5.4"
id 'io.spring.dependency-management' version "1.0.11.RELEASE"
}
group = 'com.aeonai.lib'
version = '1.0.0'
description = 'Aeon AI Library'
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
maven {
url = uri 'https://repo.osgeo.org/repository/release/'
}
maven {
url = uri 'https://repo.maven.apache.org/maven2/'
}
}
dependencies {
...
implementation 'org.geotools:gt-cql:25.2:sources#jar'
implementation 'org.geotools:gt-epsg-hsql:25.2:sources#jar'
implementation 'org.geotools:gt-geojson:25.2:sources#jar'
implementation 'org.geotools:gt-main:25.2:sources#jar'
implementation 'org.geotools:gt-opengis:25.2:sources#jar'
implementation 'org.geotools:gt-shapefile:25.2:sources#jar'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
...
}
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
bootRun.enabled = false
bootJar {
mainClass.set('NONE')
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
test {
useJUnitPlatform()
}
I am importing many of the geotools from https://repo.osgeo.org/repository/release/.
When I run gradle build all of my dependency show up as they should, but the build still fails. The compiler cannot find some of the dependencies (which I have added in a screenshot below), although I can see the files in the External Libraries tree (also in a screenshot below). I can also see the libraries in the ~/.gradle/caches.
Here is a screenshot of the files not being found.
Here is another screenshot of the files in the tree.
Why is gradle/compiler not recognizing the file is there? What else am I missing?

Gradle will not publish artifact?

Gradle v4.10.2
I’m building a Gradle Java plugin, and it builds. However when I run ./gradlew publish it does nothing, i.e., the artifact doesn’t get published. Here’s my build.gradle file (I have all the variables defined in my gradle.properties file). Also, if I just run ./gradlew publish w/o running ./gradlew build first, it doesn’t run the build phase. What am I missing in my build.gradle file? Thanks.
plugins {
id 'java'
id 'maven'
id 'maven-publish'
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
group=project.groupId
version = '0.0.1'
jar {
manifest {
attributes 'artifactId': project.artifactId,
'groupId': project.groupId,
'version': project.version
}
baseName artifactId
doLast {
println "artifactId: $project.artifactId\ngroupId: $project.groupId\nversion: $version"
}
}
dependencies {
compile gradleApi()
}
// For publishigh to S3 maven repo
publishing {
repositories {
maven {
url "s3://" + s3_bucket
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
}
RTFM. I was missing the publications block inside the publishing block. Here’s the whole block
publishing {
publications {
myLibrary(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "s3://" + s3_bucket
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
}

Deploy gradle project to Artifactory

for few days I was trying to deploy a gradle project to Artifactory, but any of my attempts were successful!
I am using Artifactory 6.1.0 and gradle on eclipe the oxygen release
I created an admin user and a gradle repository in Artifactory
I added the code [from generate setting of the repository] to the build.gradle file and here's the content
//In fact I am not sure if I need all of them!?
apply plugin: 'java-library'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
buildscript {
repositories {
jcenter()
}
dependencies {
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'xyz_reposit'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'myGroup'
artifactId = 'myProject'
version = '1.0.0'
from components.java
}
}
}
and the gradle.properties is configured
artifactory_user=Admin
artifactory_password=password
artifactory_contextUrl=http://localhost:8081/artifactory
When I execute artifactoryDeploy from publishing here the result in the cmd
When I go back to Artifactory, nothing is published in the xyz repository!? would you please help me!? I am pretty sure that something is missing in the build.gradle code?!
What gradle of version are you using? I recommend updating to the latest 5.4.1
Second, you should also have to do a gradlew artifactoryPublish after doing the artifactoryDeploy.
To see the difference in commands run:
gradlew tasks
I had the similar issue, and what me helps most is a running example
https://github.com/jfrog/project-examples/tree/master/gradle-examples/gradle-android-example

Publish Java artifact to Maven Local with Gradle

I am facing a problem when trying to install a generated jar into my local Maven Repository. The message error just show me 'task 'publish' is not found'
I am using this Gradle Script:
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
jar {
baseName = 'mongofoundry'
version = '1.0.0'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Do you have some idea Why I am reading that error message?
Thanks.
UPDATED
Running the command as #RaGe mentioned, solved the problem:
gradle publishToMavenLocal
The correct task to publish artifacts to local maven is
gradle publishToMavenLocal
Check Maven locally
For developing and testing it is useful to check library locally
gradle settings for apply plugin: 'com.android.library' not apply plugin: 'java-library'(where you can use it by default)
apply plugin: 'maven-publish'
//simple settings
project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
//setGroupId groupId
setGroupId "com.company"
//setArtifactId artifactId
setArtifactId "HelloWorld"
version "1.1"
artifact bundleDebugAar
/* add a dependency into generated .pom file
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', 'com.company')
dependencyNode.appendNode('artifactId', 'HelloWorld-core')
dependencyNode.appendNode('version', '1.1')
}
*/
}
}
}
}
to run it using command line or find this command in Gradle tab
./gradlew publishToMavenLocal
Location
artefact will be added into .m2 folder
//Unix
~/.m2
//Windows
C:\Users\<username>\.m2
//For example
/Users/alex/.m2/repository/<library_path>/<version>/<name>.<extension>
build folder
<project_path>/build/outputs/<extension>
other repositories location
~/.gradle/caches/modules-2/files-2.1/<group_id>/<artifact_id>/<version>/<id>
//For example
/Users/alex/.gradle/caches/modules-2/files-2.1/com.company/HelloWorld/1.1/c84ac8bc425dcae087c8abbc9ecdc27fafbb664a
To use it add mavenLocal(). It is important to place it as a first item for prioritise it, which is useful for internal dependencies
buildscript {
repositories {
mavenLocal()
}
allprojects {
repositories {
mavenLocal()
}
}
and
dependencies {
implementation 'com.company:HelloWorld:+'
}
*Also remember if you use a kind of shared.gradle file (via apply from) you should set path which is relevant to project.gradle (not shared.gradle)
[iOS CocoaPod local]
This is how I did it with Kotlin DSL (build.gradle.kts) for my Android library:
plugins {
id("maven-publish")
// OR simply
// `maven-publish`
// ...
}
publishing {
repositories {
// Local repository which we can first publish in it to check artifacts
maven {
name = "LocalTestRepo"
url = uri("file://${buildDir}/local-repository")
}
}
publications {
// ...
}
}
You can create all the publications with the following command:
./gradlew publishAllPublicationsToLocalTestRepoRepository
Or just a single publication with this command:
./gradlew publishReleasePublicationToLocalTestRepoRepository
See Gradle documentations: Maven Publish Plugin for more information.
Add maven plugin to your project and then:
gradle clean install
Here is an alternative skeleton for Gradle 7.5.1 with Java 17
build.gradle
plugins {
id 'org.gradle.java'
id 'org.gradle.maven-publish'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'your-group'
artifactId = 'your-artifact'
version = "0.0.1"
from components.java
}
}
repositories {
mavenLocal()
}
}
Publishing
You can see more details on the publishing steps with --info
./gradlew --info publishToMavenLocal
Output Directory
Linux/macOS
/Users/<username>/.m2/repository/your-group/your-artifact/0.0.1
Windows
C:\Users\<username>\.m2\repository\your-group\your-artifact\0.0.1

Upload only war/jar files in gradle(restrict zip/tar generation and upload)

My build script is like as follows. I use gradle build command to build and gradle upload command to upload the artifact. My problem is a tar,zip file is also generated with this command and get uploaded. I dont want it. Only things I would like to get uploaded is 'jar' and 'war' files.
I have also a related question posted by me yesterday here.
More details(I have excluded some unwanted code)
build file in root
allprojects {
apply plugin: 'maven'
group = 'groupid'
version = '1.0-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
maven {
credentials {
username "$nexusUser"
password "$nexusPass"
}
url "$nexusUrl"
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "$nexusSnapshotUrl") {
authentication(userName: "$nexusUser", password: "$nexusPass")
}
}
}
}
}
ext.comlib = [ // Groovy map literal
junit3: "junit:junit:3.8",
junit4: "junit:junit:4.9",
spring_core: "org.springframework:spring-core:3.1",
hibernate_validator : "org.hibernate:hibernate-validator:5.1.3.Final",
spring_core : "org.springframework.security:spring-security-core:4.0.2.RELEASE",
spring_security_web: "org.springframework.security:spring-security-web:4.0.2.RELEASE",
spring_security_config: "org.springframework.security:spring-security-config:4.0.2.RELEASE",
spring_boot_starter_test: "org.springframework.boot:spring-boot-starter-test:1.2.5.RELEASE",
spring_boot_starter_actuator: "org.springframework.boot:spring-boot-starter-actuator:1.2.5.RELEASE",
spring_boot_plugin_gradle: "org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE",
asciidoctor_gradle_plugin: "org.asciidoctor:asciidoctor-gradle-plugin:1.5.1",
asciidoctor_pdf_plugin: "org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.9"/*,
sl4j_api: "org.slf4j:slf4j-api:1.7.12",
sl4j_log4j: "org.slf4j:slf4j-log4j12:1.7.12",
logback_classic: "ch.qos.logback:logback-classic:1.1.3",
logback_core: "ch.qos.logback:logback-core:1.1.3"*/
]
build file in sub module
apply plugin: 'spring-boot'
group = 'com.group.id'
apply from: "../build.gradle"
apply plugin: 'org.asciidoctor.gradle.asciidoctor'
apply plugin: 'war'
description = 'module name'
dependencies {
compile "someothermodule:commonapi:1.0.0-SNAPSHOT"
compile "io.springfox:springfox-swagger2:2.0.1"
compile project(':dependingproject1:dependingproject2')
compile comlib.spring_boot_starter_actuator
compile comlib.spring_core
compile comlib.spring_security_web
compile comlib.spring_security_config
testCompile(comlib.spring_boot_starter_test) {
exclude(module: 'commons-logging')
}
testCompile comlib.junit4
providedCompile comlib_app.spring_boot_plugin_tomcat
testCompile "io.springfox:springfox-staticdocs:2.0.3"
testCompile "org.springframework:spring-test:4.1.7.RELEASE"
}
ext {
swaggerOutputDir = file("src/docs/asciidoc/generated")
asciiDocOutputDir = file("${buildDir}/asciidoc")
}
test {
systemProperty 'org.springframework.restdocs.outputDir', asciiDocOutputDir
systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir
}
//spring boot plugin
buildscript {
repositories {
maven {
credentials {
username "$nexusUser"
password "$nexusPass"
}
url "$nexusCentral"
}
maven {
credentials {
username "$nexusUser"
password "$nexusPass"
}
url "$nexusThirdParty"
}
}
dependencies {
classpath(comlib.spring_boot_plugin_gradle)
}
}
Included the following code snippet in my gradle file
[distZip, distTar].each { task -> configurations.archives.artifacts.removeAll
{ it.class.simpleName == "ArchivePublishArtifact" && it.archiveTask == task }
task.enabled = false
}
For more details refer this link. Its issue with spring boot plugin.
arjuncc's solution doesn't seem to work on Gradle 4.10.2, so here's one that works and uses public APIs, hopefully it will continue to work.
configurations.archives.artifacts.removeAll {
// exclude from the archives configuration all artifacts that were generated by distZip & distTar
def depTasks = it.getBuildDependencies().getDependencies()
depTasks.contains(distZip) || depTasks.contains(distTar)
}
More or less the same as ajuncc's solution, but perhaps a bit more simple. Remove all .tar artifacts from the archives configuration:
configurations.archives.artifacts.removeAll {PublishArtifact publishArtifact -> publishArtifact.type == 'tar'}

Resources