Gradle plugin as dependency to another module - gradle

Here is the structure:
/root
/plugin
/sample
Is it possible somehow to add locally the plugin as a dependency plugin to the sample?
So assuming that the plugin creates a plugin with the id my.example.android:1.0 I want to use the following to the sample project:
apply plugin 'my.example.android

You can do buildscript "../plugin/plugin.gradle", if it's a simple gradle script. If it is standalone then you need to publish to a repo and do the builscript + apply statements.

Related

Why do I get UnknownPluginException when trying to use a custom Kotlin complier plugin in Gradle?

I have created a custom Kotlin compiler plugin for Gradle. It was inspired by kotlin-allopen (2) and sample-kotlin-compiler-plugin, and is supposed to make all Kotlin classes non-final.
The problem is, I'm unable to use it in my projects, I only get the following:
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'no.synth.kotlin.plugins.kotlin-really-allopen' not found.
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:131)
I have tried both the "new" plugin syntax:
plugins {
id "no.synth.kotlin.plugins.kotlin-really-allopen" version "0.1"
}
.. and the old one:
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "no.synth.kotlin.plugins:kotlin-really-allopen:0.1"
}
}
apply plugin: "kotlin-really-allopen" // I've tried "no.synth.kotlin.plugins.kotlin-really-allopen" as well
So what am I doing wrong? Here's the plugin: https://github.com/henrik242/kotlin-really-allopen
EDIT: I have updated the repository with an example app and a README.md to easily reproduce the problem.
Your Gradle plugin doesn't seem to contain any entry under META-INF/gradle-plugins.
Gradle requires that every plugin ID is mapped to the implementation class, and this mapping is stored in META-INF/gradle-plugins resources.
To map the plugin ID kotlin-really-allopen, you would need a resource file
src/main/resources/META-INF/gradle-plugins/kotlin-really-allopen.properties.
See: Wiring for a custom plugin
You can also use the Gradle Plugin Development Plugin, which automatically generates these entries from the build script DSL.
Also, your repository doesn't seem to contain an actual Gradle plugin implementation, there's only the part that the compiler needs to load. For an example that contains the Gradle part too, take a look at kevinmost/debuglog.
Move apply plugin: "kotlin-really-allopen" in your build.gradle module app on top

Need help on java2wsdl using gradle

I have a java project to which I build it using gradle build and generate a war file.
Currently my requirement is to generate WSDL file at the time of build from java classes. I came to know about axis2-java2wsdl-maven-plugin and found the syntax of applying it in gradle. But I am not able to get the tasks list or the example of using this plugin in gradle to generate the WSDL file using this plugin.
Can anybody let me know of how to use this plugin or any other help so that I can generate WSDL file form my java classes.
Dependency section which I included in build.gradle:
repositories {
mavenCentral()
}
dependencies {
'org.apache.axis2:axis2-java2wsdl-maven-plugin:1.6.2'
}
axis2-java2wsdl-maven-plugin is a maven plugin not a gradle one.
Moreoever, gradle plugins must be defined in a buildscript closure or a plugins one if you want to use the new plugins DSL.
Here, you are just using the maven plugin as a regular dependency for your project.
As far as i know, there is not "java2wsdl" gradle plugin.

Is there a way to configure Gradle plugin to execute task with build?

I apply my custom plugin to project:
plugins {
id 'my.plugin.gradle-plugin' version '1.0.0'
}
This plugin contains task runMe and I want to always execute it only with build task.
The way to get it specifying in my root project:
build.dependsOn runMe
But I want to get this behavior by setting up the plugin once and don't repeat this every project which uses the plugin.
What you can do is to check in apply method if build task already exists. If so you can define a dependency there. Otherwise it's impossible.
Also, where does the build task come from? Another plugin? If so apply this plugin in you plugin and then define the dependency.

gradle - global configuraiton for buildscript

Currently, we have a buildscript{} block in all our build.Gradle files which use our custom plugin.
Is there a provision to configure buildscript block globally instead of each build.Gradle file?
For eg: I have a plugin say "MyPlugin" . This plugin has a dependency to certain jars. If this plugin is used by 100 projects, all of these 100 projects need to
specify the dependency using buildscript{}
Instead, Can I do this programmatically in settings.gradle or in init.gradle ? Like if the project is using "MyPlugin" , then add the relevant dependencies as done using build script.
Below is the solution . We can define the build script in different place and reuse across projects
https://discuss.gradle.org/t/usage-of-apply-from-in-buildscript-scope/1844

Gradle: Applying from external gradle file which is downloaded as artifact

I have a test lrg.gradle file which is supposed to do the following
lrg.gradle
dependencies {
classpath group: '<group path>', name: '<gradle file>', version: "${Version}",
}
apply from <above downloaded gradle file>
I am looking on how to apply from the above downloaded gradle file. Where will the gradle file downloaded and which variable i need to refer to access the cached location. Assuming it is stored in GRADLE_USER_HOME/caches.
Basically we want to have this in all Test LRG files so that all common tasks and dependencies can be applied from common artifact gradle file. So that they can be used like dependent tasks for the tasks defined.
You can apply from a URL like so:
apply from: "http://artifactory.url/maven/repo/$group/$name/$version/common.gradle"
That should allow you to avoid declaring a dependency on the common.gradle file.

Resources