I have groupId and artifactId, and in Kotlin code i want to get last version of artifact
i couldn't find any about this problem
I want code like this:
val data = MavenRepository.get(artifactId, groudId)
data.gel("latest")
Related
I'm publishing an artifact using maven-publish.
When I'm pushing a release artifact, the resulting artifact version is the same as the project version itself. For example if gradle.properties has version=1.2.3, the artifact would be something like foo-1.2.3.zip.
When I run a SNAPSHOT publish, the resulting artifact will include additional information in the version. For example version=1.2.4-SNAPSHOT gives foo-1.2.4-20220427.094127-1.zip. The additional information would appear to be the time and date to avoid clashes, I assume.
Is there anyway I can access this full artifact name in my gradle scripts?
If you don't specify the artifact names explicitly like this for example
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.gradle.sample'
artifactId = 'library'
version = '1.1'
from components.java
}
}
}
Then gradle will use the defaults that are taken from your build.gradle, gradle.properties and the module directory names.
I'm not sure if there's a way to configure the mavenPublish plugin to print out the maven artifact upon publishing, but you can look in your ~/.m2 directory to see what exactly has been published to your local if you run ./gradlew publishToMavenLocal
I'm also thinking you could create a custom task to print out the group, artifact and version, something like this in the build.gradle of your project you are publishing:
project.task('getMavenCoordinates') {
doLast {
println "Maven Artifact: ${project.group}:${project.name}:${project.version}"
}
}
project.task("publishToMavenLocal").dependsOn("getMavenCoordinates")
If you wanted to configure the task to run after a different maven-pubish task, just change it accordingly! But something like that could help achieve what you want.
I'm using mongodb with Spring Boot. Recently, my mongodb was upgraded to version 3.0.
I'm using the following Gradle dependencies for Spring:
buildscript {
ext {
springBootVersion = '1.2.6.RELEASE'
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
If I look on maven repositories for Gradle: 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.6.RELEASE', I see the following (http://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/1.2.6.RELEASE):
The dependencies for the mongo-java-drivers are 2.12.5 under the "Version" column. I was wondering what the "Update" column is there for and how can I use the version of the mongo-java-drivers listed there instead (3.0.4)?
Since I'm using mongo 3.0, I would like to use the 3.0.4 java-drivers instead of 2.12.5 as I need to update my java-drivers to be at least 2.13 before they will work with my mongodb 3.0: http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-drivers
Just add the following dependency to your project dependencies:
compile 'org.mongodb:mongo-java-driver:3.0.4'
This will explicitly set there mongodb Java driver to the newest version and will overrun the transitive dependency version of spring-boot-starter-data-mongodb.
BTW, the "Updates" column means the newest version for a specific Artifact.
You can force the usage of a newer version of a dependency by just explicitly adding the dependency version that you want to use in the pom.xml.
Then Maven will use the explicitly specified version to compile.
FYI, you can exclude a dependency triggered by a direct dependency by using the exclude element.
See this doc to know how maven manages dependencies.
If you are using Gradle, see this page. In fact, you exclude the MongoDB transitive dependency triggered by spring boot and you explicitly add the latest version as a direct dependency.
I`m trying to publish mutliple artifacts per project.
How to upload an existing collection of 3rd-party Jars to a Maven server in Gradle?
I have tried to apply this solution -
My build.gradle looks like: https://gist.github.com/anonymous/01b31c26eca7a507c14f
I tried to follow the documentation: http://www.gradle.org/docs/current/us...
What I`m getting is:
What went wrong: Execution failed for task ':install'. Could not publish configuration 'archives' > A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact my:jar:jar:null, trying to add MavenArtifact my:jar:jar:null.
My env: Gradle 2.2.1
Build time: 2014-11-24 09:45:35 UTC Build number: none Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.7.0_71 (Oracle Corporation 24.71-b01) OS: Windows 8.1 6.3 amd64
Thanks for your help.
Hi currently i've same problem, but in different context. I'm using proguard in my java project, and i would like have two different artifacts using obiuvsly gradle.
I've made a Proguard task which is producing an obfuscated .jar :
task proguard(type: proguard.gradle.ProGuardTask)
{
injars 'build/libs/foundation.jar'
outjars 'build/libs/foundationObfuscated.jar'
}
In a second time we need to add our new artifact to the default one :
artifacts
{
archives(file: file("$projectDir/build/libs/foundationObfuscated.jar"),
builtBy: proguard)
{
classifier = 'obfuscated'
}
}
The most important thing you need to add a new 'classifier' different from the default one. In this configuration i also specify my archive depends on the previous task ('proguard').
Finally we can upload the two artifacts :
uploadArchives {
repositories.mavenDeployer {
pom.groupId = 'com.groupid'
pom.artifactId = 'artifactid'
pom.version = "${versionMajorDevelop}.${buildTime()}"
repository(url: "file://${workingLocalDirArtifact()}")
}
}
Here i'm specifiy i would like to publish the two different artifacts (the generic one and the '${versionMajorDevelop}.${buildTime()}-obfuscated'
in a local repository 'workingLocalDirArifact' but you can use another configuration.
By default Gradle will run proguard task, and you will have published the multiple artifacts.
I cannot access gist.github.com as my employer kindly blocked it. Thus I don't know what exactly would you like to achieve. Publish 3rd party jars as in the link you posted or rather your own additional artifact built from the project.
If the latter don't bother with nasty scripting, that's fully supported by Gradle. Error you posted says everything.
A POM cannot have multiple artifacts with the same type and classifier.
You need to specify classifier for any additional artifact.
Let say you are about to upload a zip with deployment bundle (your jar plus libs). It would look like:
task('applicationBundle', type: Zip) {
classifier = 'distro'
// ... code for zipping appropriate files
}
artifacts {
archives applicationBundle
}
I haven't tested the above example but that should do it.
A word of explanation - classifier going to be appended to the artifact file name as a suffix.
EDIT: if you are using new incubating API of maven-publish plugin for interacting with Maven here is relevant example for you (publishing additional jar with sources): http://www.gradle.org/docs/current/dsl/org.gradle.api.publish.maven.MavenPublication.html
In a gradle project, I have my dependencies set as:
dependencies {
compile group: 'com.our_organization.lib', name: 'Libraries', version: '5.+'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
}
which uses the latest released version of Libraries, and works perfectly.
I then release my built jar to Artifactory via:
artifactory {
contextUrl = artifactory_contextUrl
publish {
repository {
repoKey = publicationRepoKey
username = artifactory_user
password = artifactory_password
maven = true
}
}
}
which for the most part works fine.
However, when I go to artifactory and get the xml for any given version, it's dependencies are listed as
<dependencies>
<dependency org="com.our_organization.lib" name="Libraries" rev="5.+" />
<dependency org="commons.io" name="commons.io" rev="2.4" />
</dependencies>
which means I am unable to link my version to the specific Libraries version that was used for its build.
What I'd like to do is have the dependency version given to artifactory be the specific resolved version that is used in the build.
I've scoped a couple of things, all very hacky, and feel there has to be a better way.
Here's what I've thought of / tried:
Resolving the dependency myself and setting the specific version in the gradle dependency dsl, so to gradle it looks like a specific version. Using ivy to get the resolved version of a dependency of proving to be harder that it should.
Mucking the xml after its written but before it's sent to artifactory. This is just bad on so many levels and prone to breaking in the future.
Using a seperate gradle project to determine the resolved version and write that to a properties file which is then used similarly to #1. This feels like overkill.
Overall, this seems like a simple for which, for the life of me, I can't find an appropriate solution.
I am not sure what Gradle will do with it in pom.xml, but you might try using the Artifactory's functionality to retrieving the latest version, instead of Gradle's one.
The post
In Gradle, how can I generate a POM file with dynamic dependencies resolved to the actual version used?
exactly solves this problem. But you have to use the maven-publish Plugin instead of the Artifactory Plugin.
What I have is a maven repository (nexus) to which maven has been publishing. In each artifact version folder in my artifact repository folder there are the standard maven artifacts: a maven-metadata.xml, a jar, and a pom.xml, etc.
Now I want to resolve these using gradle. In my gradle.build file if I list them as:
dependencies {
compile group: 'com.company', name: 'artifact', version: '1.0-SNAPSHOT'
}
Then they will resolve correctly. However, I want to use the version "latest.integration" so that I can automatically integrate the latest versions of my dependencies. When I do this though, gradle fails to resolve it.
I imagine that gradle is looking for some ivy specific files that maven is not publishing up to the repository in order to resolve latest.integration, but I am not sure. Should I go back and re-publish all of my upstream dependencies with gradle before trying to resolve down stream? It would seem that since gradle supports maven repositories under the repositories element that it should already know how to interpret "latest.integration" for that repository type.
This is my repositories section:
repositories {
mavenCentral()
maven { url "http://<server>/nexus/content/repositories/snapshots" }
}
Thank you for any help you can provide
latest.integration is an Ivy concept, and only works for Ivy repositories. In other words, both publication and consumption would have to happen in an Ivy-compatible manner. (Gradle is capable of this; not sure about Nexus.)
The obvious alternative is to use Maven snapshot dependencies. What do you hope to gain from using latest.integration?