Add plugin dependency in grails - maven

I am trying to add dependency of a plugin into my grails application, but it doesnot have any plugins in grails repo. It can be added to maven project as :
<dependency>
<groupId>com.plaid</groupId>
<artifactId>plaid-java</artifactId>
<version>0.2.12</version>
</dependency>
As my project is also maven based. How do i add this plugin into my project.
P.S. : IT cannot be added in plugins and dependencies since there is no grails plugin associated with that.
Any help is appreciated.

You can use the create-pom org.mycompany to create your pom.xml file to make grails read the pom.xml you need to set in BuildConfig.groovy this code
grails.project.dependency.resolution = {
/*YOUR CONFIG*/
pom true
repositories {
/*YOUR RESPOSITORIES*/
}
}
Then you need to add your dependency in this pom.xml
You can see the official doc. in this link

We can add dependency for any plugin in grails under dependencies{} in BuildConfig.groovy as:
<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
For your case, the equivalent for:
<dependency>
<groupId>com.plaid</groupId>
<artifactId>plaid-java</artifactId>
<version>0.2.12</version>
</dependency>
is:
dependencies{
compile "com.plaid:plaid-java:0.2.12"
}
For more you can have a look into http://docs.grails.org/2.3.1/guide/conf.html

Related

How to use gradle feature variant dependecies in tests?

I am migrating a Maven library project to Gradle. The original project also has optional dependencies. I use the java-library plugin but moving the formerly optional dependencies to implementation results in runtime dependencies instead of compile. So I tried the gradle feature variants which results in the right dependencies in the pom.xml. But doing so results is failing test compile as the dependencies of the feature variant are missing on the test compile classpath!
Here is my current setup in build.gradle:
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
java {
registerFeature('oSupport') {
usingSourceSet(sourceSets.main)
}
}
dependencies {
api 'my.compile:dep-a:1.0.0'
implementation 'my.runtime:dep-i:1.0.0'
oSupportApi 'my.optional:dep-o:1.0.0'
}
Let's assume there is a class O available from my.optional:dep-o. If I import O in any class in src/main/java it works perfectly. Also the dependencies are exported right to Maven (using gradle generatePomFileForMavenJavaPublication, see the dependencies from the generated pom.xml below). But any test in src/test/java using class O will not compile (import my.optional.O; creates error: package my.optional does not exist)
<dependencies>
<dependency>
<groupId>my.compile</groupId>
<artifactId>dep-a</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>my.rintime</groupId>
<artifactId>dep-r</artifactId>
<version>1.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.optional</groupId>
<artifactId>dep-0</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
How to solve this? I know I could have used the nebula.optional-base plugin instead of the buildin Gradle feature variant but I would prefer the new gradle builtin support for optional dependencies instead.
PS: I use Java 8 and Gradle 5.6.2
This looks like a bug when the feature source set uses the main source set. Can you report on https://github.com/gradle/gradle/issues?
In the meantime, this should fix it:
configurations {
testCompileClasspath.extendsFrom(oSupportApi)
testRuntimeClasspath.extendsFrom(oSupportApi)
testRuntimeClasspath.extendsFrom(oSupportImplementation)
}
Really weird, I agree with #melix this seems to be a Gradle bug.
The following will fix it but should not be needed, imho:
dependencies {
api 'my.compile:dep-a:1.0.0'
implementation 'my.runtime:dep-i:1.0.0'
oSupportApi 'my.optional:dep-o:1.0.0'
testImplementation(project(":${project.name}")) {
capabilities {
requireCapability("${project.group}:${project.name}-o-support")
}
}
}
For this simplified setup with only one feature dependency could be replaced by testImplementation 'my.optional:dep-o:1.0.0' but for a general larger dependency list this approch avoids repetition of the dependencies as the extendsFrom solution of #melix.

How to use pom type dependency in Gradle

I need to produce transitive dependency from my Java library which is of type pom. Here is an example on how I'm doing it:
plugins {
`java-library`
`maven-publish`
}
repositories {
// some maven repo
}
dependencies {
// This is POM type dependency:
api("org.apache.sshd:apache-sshd:1.6.0") {
exclude(group = "org.slf4j")
}
}
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
The problem with this configuration is that in the published pom.xml of my library the dependency is of type jar (by default) and declared like that:
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>apache-sshd</artifactId>
<version>1.6.0</version>
<!-- Should declare pom type -->
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.slf4j<groupId>
</exclusion>
</exclusions>
</dependency>
So when I try to use my published library from another project it fails as there is no such artifact as apache-sshd because it's type should be pom. So how to correctly publish desired dependency using Gradle?
Running on Gradle 5.3.1 with Kotlin DSL.
Try to use following construction for declaring dependency in Gradle
api("org.apache.sshd:apache-sshd:1.6.0#pom") {
exclude(group = "org.slf4j")
isTransitive = true
}
Looks like Gradle consumes all dependencies as jar type by default. And Maven plugin generates dependency section in pom file by using this extracted type. For pom dependency it is necessary to put correct value into type field of generated file. But if you put pom extension for your dependency, Gradle won't resolve transitive dependencies that are declared in this artifact. Set the value of transitive flag resolves this issue.
I have used it in the following way:
compile(group: "dependency_group", name: "dependency_name", version: "dependency_name", extension: "pom")
and if you want to exclude the transitive dependencies
add transitive flag and set it to false
compile(group: "dependency_group", name: "dependency_name", version: "dependency_name", extension: "pom"){
transitive = false
}

How to include custom type converter using Maven and Grails

I am working on a Grails project that needs to compile with both Grails and Maven. Everything worked great except for my GSON converter I added (using the grails-gson plugin). Now I get the following when I run mvn install.
unable to resolve class grails.plugin.gson.converters.GSON
Anyone know how to overcome this
Plugin has to be added as a dependency in pom.xml too
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>gson</artifactId>
<version>1.1.4</version>
<type>zip</type>
</dependency>
Mavenized grails project refer pom file for all dependencies (including plugin dependencies).

pom dependency fails in Gradle (ok in Maven)

I'm writing a standalone EJB client for JBoss 7.1 and as suggested I'm using the following dependency:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<type>pom</type>
<version>7.1.1.Final</version>
</dependency>
This works as expected in Maven, however when used in Gradle like so:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final'
}
It fails with:
Could not find group:org.jboss, module:jboss-remote-naming, version:1.0.2.Final.
What is the reason for different behavior of Gradle vs. Maven?
Well the dependency you declare in Maven points to a pom packaging component, and the one in Gradle points to a jar. However there is no jar with this project since it is a pom packaging component so Gradle obviously fails.
http://search.maven.org/#browse%7C351478366
Using Gradle you probably have to either declare a dependency to the pom somehow (not sure if that is possible) or add the dependencies from the pom to your project yourself.
http://search.maven.org/remotecontent?filepath=org/jboss/as/jboss-as-ejb-client-bom/7.1.3.Final/jboss-as-ejb-client-bom-7.1.3.Final.pom
Use the #pom type:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final#pom'
}

mojo-executor support for plugin dependencies?

I'm using the mojo-executor library to call a number of Maven plugins from within another Maven plugin.
However, I can't find any way to specify dependencies on the plugins as I'm invoking them. This is an issue for the maven-assembly-plugin, where I need to add an assembly descriptor file as a dependency. Adding the dependency at another level doesn't seem to get the descriptor file onto the plugin's classpath.
Any idea if this is possible, or if mojo-executor could be improved to provide this functionality? Thanks.
The mojo-executor will execute the mojo in an environment without any classpaths.
You need to manually add the dependency.
Dependency dep = new Dependency();
dep.setGroupId("groupId");
dep.setArtifactId("artifactId");
dep.setVersion("0.0.1-SNAPSHOT");
Plugin assembly = MojoExecutor.plugin(
"org.apache.maven.plugins",
"maven-assembly-plugin",
"2.3");
assembly.addDependency(dep)
MojoExecutor.executeMojo(assembly,
MojoExecutor.goal("single"),
...
)
You know that it's possible to define dependencies for plugins as well:
<plugin>
<groupId>com.soebes.maven.plugins.mlv</groupId>
<artifactId>maven-license-verifier-plugin</artifactId>
<version>0.4</version>
<dependencies>
<dependency>
<groupId>com.company.licenses</groupId>
<artifactId>allprojects</artifactId>
<version>1.0</version>
</dependency
</dependencies>
<configuration>
<!-- Optional you can put your configurations here -->
</configuration>
</plugin>
This will put the dependency on the classpath of the plugin. That might solve your problem.
Maybe you need to place a requiresDependencyResolution parameter at the #Mojo annotation of our Maven plugin's goal class. Something like this:
#Mojo(name = "your-goal", defaultPhase = LifecyclePhase.xxx,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME
)
public class YourGoalMojo...
This is necessary for YOUR Maven plugin to have dependencies resolved and available before/to its execution. The mojo-executor project's README page mentions this just after its maven-dependency-plugin based example:
https://github.com/TimMoore/mojo-executor/blob/master/README.md
Further information about the #Mojo annotation parameterization can be found here:
http://maven.apache.org/developers/mojo-api-specification.html

Resources