How to use snapshot repository for openapi gradle plugin? - gradle

I would like to use snapshot repository for open API generator in Gradle. However it still cannot find the plugin.
settings.gradle.kts
pluginManagement {
repositories {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openapi.generator") version "6.3.0-SNAPSHOT"
}
Error:
Plugin [id: 'org.openapi.generator', version: '6.3.0-SNAPSHOT'] was not found in any of the following sources:
It seems like it is still pointing to the gradle plugin portal.

The URL of the snapshot is
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-gradle-plugin/6.3.0-SNAPSHOT
You need to update groupId (org.openapitools) and artifactid (openapi-generator-gradle-plugin)

Related

Spring native can't be found

Can't add spring native to an existing project, if I create a new one with spring native selected it works.
org.gradle.internal.exceptions.LocationAwareException: Build file
'/Users/jakob/Documents/worklivery-backend/build.gradle.kts' line: 6
Plugin [id: 'org.springframework.experimental.aot', version: '0.10.4']
was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
plugins{
...
id("org.springframework.experimental.aot") version "0.10.4"
}
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/release") }
}
The AOT plugin isn't published to Gradle's plugin portal, it's only available from https://repo.spring.io. You need to add some configuration to your project's settings.gradle file so that it can be resolved:
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/release' }
mavenCentral()
gradlePluginPortal()
}
}
The above matches the configuration from a project generated by https://start.spring.io and adds Maven Central and https://repo.spring.io/release to the plugin repositories in addition to the default Gradle Plugin Portal.

Google Cloud Artifact Registry for Gradle plugins

I have successfully published to Artifact Registry, and I can use artifacts from there in "normal" use: dependencies { implementation("mygroup:myartifact:myversion") }.
My issue is plugins. I have created a plugin. I can successfully publish it to Artifact Registry and also to Maven local. I can use it from Maven local, but I can't get my build script to take it from Artifact Registry.
buildscript {
repositories {
maven(url = uri("artifactregistry://us-west1-maven.pkg.dev/glitchy-maven/repo"))
}
}
plugins {
id("com.google.cloud.artifactregistry.gradle-plugin") version "2.1.1"
id("com.glitchybyte.gradle.plugin.buildinfo") version "1.0.0"
`java-library`
}
And I get:
* What went wrong:
Plugin [id: 'com.glitchybyte.gradle.plugin.buildinfo', version: '1.0.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.glitchybyte.gradle.plugin.buildinfo:com.glitchybyte.gradle.plugin.buildinfo.gradle.plugin:1.0.0')
Searched in the following repositories:
Gradle Central Plugin Repository
So, it's not looking into Artifact Registry for plugins. I know I'm missing something, but I don't know what.
...Update...
I removed buildscript from build.gradle.kts, and instead I added this to settings.gradle.kts:
pluginManagement {
plugins {
id("com.google.cloud.artifactregistry.gradle-plugin") version "2.1.1"
}
repositories {
maven(url = uri("artifactregistry://us-west1-maven.pkg.dev/glitchy-maven/repo"))
}
And I get:
* What went wrong:
Error resolving plugin [id: 'com.glitchybyte.gradle.plugin.buildinfo', version: '1.0.0']
> Could not resolve all dependencies for configuration 'detachedConfiguration1'.
> Not a supported repository protocol 'artifactregistry': valid protocols are [http, https, file, gcs, s3, sftp]

Gradle apply plugin vs plugins

I have a simple plugin with greet task doing some 'Hello World' print.
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
}
group = 'standalone.plugin2.greeting'
version = '1.0'
gradlePlugin {
plugins {
greeting {
id = 'standalone.plugin2.greeting'
implementationClass = 'standalone.plugin2.StandalonePlugin2Plugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'standalone.plugin2.greeting'
version = '1.0'
from components.java
}
}
}
Now, I have runner application to just run the greet task
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'standalone.plugin2.greeting:standalone-plugin2:1.0'
}
}
apply plugin: 'standalone.plugin2.greeting'
With apply plugin natation it works OK, but when I use plugins notation instead like this:
plugins {
id 'standalone.plugin2.greeting' version '1.0'
}
it doesn't work.
The error message is:
* What went wrong:
Plugin [id: 'standalone.plugin2.greeting', version: '1.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'standalone.plugin2.greeting:standalone.plugin2.greeting.gradle.plugin:1.0')
Searched in the following repositories:
Gradle Central Plugin Repository
What is the difference? According to documentation apply plugin is old and should not be used.
Before the introduction of the plugins block, plugin dependencies had to be resolved in the same way as regular project dependencies using a combination of repositories and dependencies. Since they need to be resolved before running the actual build script, they need to be defined in the special buildscript block:
buildscript {
repositories {
// define repositories for build script dependencies
}
dependencies {
// define build script dependencies (a.k.a. plugins)
}
}
repositories {
// define repositories for regular project dependencies
}
dependencies {
// define regular project dependencies
}
Once the dependencies were resolved, they could be applied using apply plugin:.
By default, the new plugins block just resolves the plugins from the Gradle Plugin Repository. This is a regular Maven repository, so it can be used using the old way, too:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
In your case, the plugin only exists in mavenLocal, so the plugins block cannot resolve it, as it only looks into the Gradle Central Plugin Repository. You may use the pluginManagement block to resolve plugins from custom repositories.
As described in the article linked above, it is necessary to create a link between the plugin identifier (used inside the plugins block) and the Maven coordinates that provide the respective plugin. To create this link a marker artifact following a specific convention must be published. The Gradle Plugin Development Plugin automatically publishes this marker artifact if used in combination with the Maven Publish Plugin.

nothing published to artifactory using gradle artifactory plugin

I followed the solution given here: upload artifact to artifactory using gradle, but it is not working for me.
Here is my code:
apply plugin: 'artifactory'
apply plugin: 'maven-publish'
/* Specify the repositories to be used for downloading artifacts */
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
/* Define the repository (in artifactory) where artifactoryPublish task should publish */
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = "${artifactory_repoKey}"
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
defaults {
publications ('integTestPublish')
}
}
publishing {
publications {
integTestPublish(MavenPublication) {
setArtifactId(project.name + '-' + integTestJar.appendix)
artifact integTestJar.archivePath
}
}
}
The error is:
> Could not find method defaults() for arguments [build_3a14r6bjhcvi883gaucf1jd8f0$_run_closure1_closure5_closure9#71bc1581] on root project 'samples'.
GAV used for artifactory plugin is:
classpath group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.1.0'
What is wrong here ? can someone point me to DSL/API doc of artifactory plugin version 2.1.0
My gradle version is 1.11
As explained in the user guide, artifactory plugin of version 2.X is intended to work with maven plugin, not maven-publish plugin. For working with publications please use artifactory-publish plugin of version 2.X, or, preferably, use version 3.0 of com.jfrog.artifactory plugin. It is intended to work with maven-publish publications and compatible both with Gradle 1 and Gradle 2.
This answer contains a fully working example.

Publishing artifact from gradle project to bintray (maven repository)

I have configured Gradle to publish project artifact using new Maven Publisher Plugin, unfortunately this plugin has problem with dependency in generated pom.xml - dependencies has scope runtime instead of compile.
My configuration is like this:
apply plugin: 'maven-publish'
publishing {
publications {
mavenCustom(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://api.bintray.com/maven/codearte/public/fairyland"
credentials {
username = bintrayUser
password = bintrayKey
}
}
}
}
Publishing was simple with one command:
gradle publish
How to achieve this in old (working) way? Is possible to automate project taging when project is released?
Ok, I figured it out:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
name = 'Codearte Public Repository'
repository(id: 'codearte-repository', url: 'https://api.bintray.com/maven/codearte/public/fairyland'){
authentication(userName: bintrayUser, password: bintrayKey)
}
}
}
Uploading with command:
gradle uploadArchives
The fact that all POM dependencies have runtime scope is a known limitation of the new, incubating maven-publish plugin. Until this gets fixed, you can either fix it up yourself by using the publication.pom.withXml hook, or fall back to the maven plugin. Both plugins are documented in the Gradle User Guide.
Tagging is an entirely different question. You can either use one of the third-party Gradle SCM plugins or call out to a command line tool (e.g. with an Exec task).

Resources