Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit Gradle plugin to plugins.gradle.org #107

Closed
sdavids opened this issue Jun 22, 2016 · 10 comments
Closed

Submit Gradle plugin to plugins.gradle.org #107

sdavids opened this issue Jun 22, 2016 · 10 comments
Assignees

Comments

@sdavids
Copy link

sdavids commented Jun 22, 2016

Please submit your Gradle plugin to the Gradle Plugin Portal:

https://plugins.gradle.org/docs/submit

It would simplify Gradle build files.

Instead of:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'de.thetaphi:forbiddenapis:2.2'
  }
}

apply plugin: 'de.thetaphi.forbiddenapis'

One would only need:

plugins { id "de.thetaphi.forbiddenapis" version "2.2" }

See: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block

@uschindler
Copy link
Member

Hi,

I can look into this, but as forbidden-apis is not a Gradle project, it cannot easily use the plugin publishing API (no connector from Apache Ant). No idea how to publish it there.

For several reasons, forbiddenapis cannot be built with Gradle at the moment (e.g., gradleApi() classpath pollution is a blocker, which should have been fixed in newest Gradle version).

BTW: forbiddenapis is also available on jcenter() repo, so Gradle should find it by default.

@uschindler
Copy link
Member

uschindler commented Jun 23, 2016

Wht I can do at least is providing the plugin marker artifact: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers

Publishing in Gradle's repository is impossible. Using the marker artifact, it would reduce the above code to:

pluginRepositories {
  mavenCentral()
}

plugins { id "de.thetaphi.forbiddenapis" version "2.2" }

@uschindler uschindler self-assigned this Jun 23, 2016
@sdavids
Copy link
Author

sdavids commented Aug 29, 2018

This would be much appreciated -- especially for use with the Kotlin DSL

https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/#configuring-plugins

@uschindler
Copy link
Member

Hi,
thanks Sebastian. I think I found a solution how to publish the plugin to the Gradle Plugin portal. Actually that is not easy, because by default it only works for plugins that were created by a gradle build, so it tries to run the tasks 'compile*', 'jar', 'javadocs',... and then also relies on the artifact name.
The trick was to disable all the basic tasks of the java plugin that generate the artifacts (plugin jar, source jar, javadocs) and replace by a copy task, that uses a separate configuration to download the real plugin artifacts from Maven Central, put them at the same place like the jarred artifacts of the disabled tasks and then publish those using the plugin. This was not so easy to figure out, as there is no documentation about the plugin internals nor any source code available. To me, the Gradle Plugin Portal looks like a not very open source friendly blackbox.

The plugin is waiting for approval and I need them to delete it again (i did some test uploads, but there are now broken artifacts in the plugin portal).

The current state, including the used build.gradle file (just for this download from Maven push to Gradle one) can be found in their forum: https://discuss.gradle.org/t/please-remove-test-upload-of-plugin-which-is-not-yet-approved-anyways/28456

Once this is all sorted out, I will push all versions since 2.0 also to the Gradle Plugin portal.

@uschindler
Copy link
Member

Here is the gist with my "publish hack": https://gist.github.com/uschindler/8af468efe73aaded3d8e25f265e5e192

@uschindler
Copy link
Member

The 2.x series of the plugin (1.x has no Gradle support) were released through the plugin portal. I did a quick test, all seems fine: https://plugins.gradle.org/plugin/de.thetaphi.forbiddenapis

Could you check it, because I can delete and re-upload them for up to 7 days.

@sdavids
Copy link
Author

sdavids commented Sep 2, 2018

build.gradle.kts

plugins {
  java
  id("de.thetaphi.forbiddenapis") version "2.5"
}

repositories {
  jcenter()
}

group = "test"
version = "1.0.0"

java {
  sourceCompatibility = JavaVersion.VERSION_1_8
  targetCompatibility = JavaVersion.VERSION_1_8
}
* Where:
Build file '/Users/dev/tmp/forbiddenapis/build.gradle.kts' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'de.thetaphi.forbiddenapis', version: '2.5']
> Failed to apply plugin [id 'de.thetaphi.forbiddenapis']
   > Cannot execute Groovy script for apply(Project).
      > Forbidden-apis only works in projects using the java plugin.

Same with:

build.gradle

plugins {
  id 'java'
  id 'de.thetaphi.forbiddenapis' version '2.5'
}

repositories {
  jcenter()
}

group = 'test'
version = '1.0.0'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
* Where:
Build file '/Users/dev/tmp/forbiddenapis/build.gradle' line: 3

* What went wrong:
An exception occurred applying plugin request [id: 'de.thetaphi.forbiddenapis', version: '2.5']
> Failed to apply plugin [id 'de.thetaphi.forbiddenapis']
   > Cannot execute Groovy script for apply(Project).
      > Forbidden-apis only works in projects using the java plugin.

@uschindler
Copy link
Member

This is a completely different issue and has noting to do with this one. Which Gradle version? Can you post the full stacktrace in a new issue?

@uschindler
Copy link
Member

In my own check it works, by the way (Gradle 3.3 and Gradle 4.3).

@uschindler
Copy link
Member

This looks like an issue with order of initialization. The new plugin mechanism initializes the forbidden plugin first, and this causes the error message.

The reason for this is: The plugin does not explicitly load the java plugin, instead it just looks if it's there. Other plugin do it in the same way.

The better way to handle this would be to load the JavaBasePlugin first using apply(). This cannot be fixed for existing versions out there. But this is a new issue, so I'd open a new one.

BTW, sometimes it works, depending on which other plugin you actually have in your gradle file. It looks like Gradle initializes 3rd party plugins first (I have no idea why).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants