How to determine plugin id for 3rd party gradle plugin library? - gradle

For integration test requirement I want to use gradle plugin 'gradle-processes':
https://github.com/johnrengelman/gradle-processes
So I have added version(0.3.0 is only version I see without our organization) in classpath dependency :
dependencies {
classpath 'com.github.jengelman.gradle.plugins:gradle-processes:0.3.0'
}
along with
apply plugin: 'com.github.jengelman.gradle-processes'
But gradle run fails stating that:
Plugin with id 'com.github.jengelman.gradle-processes' not found.
In my local machine repo I can see the jar get downloaded properly, only issue is I am unable to understand what plugin Id I should apply.
Even I went through
https://github.com/johnrengelman/gradle-processes but couldn't get the answer.
Any help to understand how plugin id get determined for a plugin will be really helpful.
Thanks,

Understood the plugin Id concept, so may be useful reference for someone else
https://guides.gradle.org/writing-gradle-plugins/#declare_a_plugin_identifier

Related

Load Gradle plugin from custom plugin, dynamically

I am developing a Gradle plugin (https://github.com/hkhc/jarbird), which apply some other plugins in the code according to different scenarios.
I can do that by putting the plugin components as implementation dependencies in my plugin project. Then apply the project with project.apply() method with plugin ID or plugin class object.
However, this means unnecessary downloads of plugin components when I don't need those plugins. So I am finding a way to resolve the plugins dynamically.
I tried to do that by adding the dependency as compileOnly in the build script of my custom plugin, and load it in project.apply() of my plugin.
val artifactoryConfiguration = project.buildscript.configurations.detachedConfiguration(
DefaultExternalModuleDependency(
"org.jfrog.buildinfo",
"build-info-extractor-gradle",
"4.23.4"
)
)
artifactoryConfiguration.resolve()
When I made the coordinate wrong intentionally, I got ModuleVersionNotFoundException. So I am sure the resolve did take place. However, project.apply(ArtifactoryPlugin::class.java) still cause ClassNotFoundException when executing the plugin. It seems Gradle cannot load the plugin from a random detached configuration.
I got stuck at this point, and don't know how to make Gradle load a plugin that I resolve dynamically in my custom plugin.
Do I get the direction wrong or I missed something that makes this approach work?

How to manually add dependencies to Gradle's MavenPom/MavenPublication?

I am working on a plugin. This plugin gets attached to a project that does not apply the java plugin nor the java-library plugin but which should functionally "look" like a Java project[1]. Which means that it should publish a POM including dependencies. The exact dependencies are known and have been collected in a Configuration.
However, I cannot figure out how to manually attach dependencies to the MavenPublication such that they make it into the published pom (aside from directly editing the pom xml).
MavenPublication shadowMavenPublication = publishingExtension.getPublications().create( "mavenShadowArtifacts", MavenPublication.class );
// `shadowPublishArtifact` is a class defined in the plugin
shadowMavenPublication.artifact(
shadowPublishArtifact.getFile(),
(mavenArtifact) -> {
mavenArtifact.setClassifier( shadowPublishArtifact.getClassifier() );
mavenArtifact.setExtension( shadowPublishArtifact.getExtension() );
}
);
So at this point I have the MavenPublication and added my custom artifact to it. Internally this MavenPublication contains a number of "dependencies" as instances of MavenDependency. E.g. DefaultMavenPublication#runtimeDependencies, DefaultMavenPublication#apiDependencies, ... But those are things defined on internal-only contracts.
Using just public APIs, how can I add dependencies to get added to the pom?
P.S. As a bonus, answer the question on the Gradle forums and get points there too! :D
P.S.S. These dependencies come from another project (hibernate-core) in a multi-project build. The user has configured those dependencies themselves. I just "consume" those dependencies with a series of "dependency substitutions". That "source project" defines some exclusions to its dependencies. How can I access those exclusions do be able to transfer them to the dependencies I am creating for this copy project (hibernate-core-jakarta)?
Thanks!
[1] Its a long back-story, but the gist is that this plugin integrates the JakartaTransformer. The project is completely generated using the transformer. The tasks added by those 2 plugins cause problems.
MavenPublication class has pom property - You need to construct (or provide in Your plugin some API for that purpose) pom with all necessary dependencies. It will be published alongside with artifact.
As far as I know, dependencies are attached to the POM by evaluating the configurations of a software component: MavenPublication.from(SoftwareComponent) (source: DefaultMavenPublication).
The idea would be to provide a customized software component. This is only possible through a custom plugin, according to Creating and publishing custom components.

what is the javaagent.jar dependency from appD

I need to add this to the central repository. But appD does not give its details such as group id, artifact id etc to add in the proper path. What would that be?
AppDynamics doesn't provide it as a Maven dependency and I think it makes sense as well as it there is no application code which needs to call the java agent jars method.
But If you want to make it as a Maven dependency(Maybe so that in your organisation you have a same version of jar used everywhere and provide an easy way to get the jar, which IMO is a good practice), then you have to download java agent jar and put it in your private/public maven repository.
Please see this answer on how to place your own jars to Maven.

Programmatically determine Gradle version from within Gradle plugin

How can I retrieve the version of Gradle itself programmatically from within a Gradle plugin?
Just found out one can get at it using either
getProject().getGradle().getGradleVersion()
Javadoc and DSL reference for the Gradle core type which contains the version. Accordinng to the javadoc getVersion will never return null.
or
Plugin.class.getPackage().getImplementationVersion()
This is plain groovy/java class-based and depends on the classloader and provided Manifest.
This question appeared as the first result when I Googled for it.
There's a class - GradleVersion that'll do the job as well. So
GradleVersion.current();
will return the same as
getProject().getGradle().getGradleVersion()

Transitive dependencies within my plugin with maven 2

I'm trying to get all dependencies (include transitives) within my plugin using mavenProject.getArtifacts() but get an empty Set. part of the dependencies which I have to get cannot be resolved. I know that Maven 3 offers the #requiresDependencyCollection but that is no use for me since I must use Maven 2. What can I do?
https://svn.apache.org/repos/asf/maven/shared/trunk/maven-artifact-resolver will help with this.
For an example of its use, see https://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/codegen-plugin.

Resources