How can I build a Gradle plugin with Maven - maven

It's possible to build a Gradle plugin with Maven. Which dependencies are needed?

Yes, it's possible. We do so with Spring Boot's Gradle plugin using these dependencies:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gradle</groupId>
<artifactId>gradle-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gradle</groupId>
<artifactId>gradle-base-services</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gradle</groupId>
<artifactId>gradle-base-services-groovy</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gradle</groupId>
<artifactId>gradle-plugins</artifactId>
<scope>provided</scope>
</dependency>
Groovy's in Maven Central, but the Gradle dependencies are in their own repo: http://repo.gradle.org/gradle/libs-releases-local

Related

Why does every pom file published by Gradle has a self-referential dependency?

When I try to convert a project from maven/sbt to Gradle:
https://github.com/tek/splain/blob/nexusRelease/Dev1/build.gradle.kts
I found a few problems, when comparing the new published pom file (by gradle):
...
<modelVersion>4.0.0</modelVersion>
<groupId>io.tryp</groupId>
<artifactId>splain_2.13.6</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.13.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.tryp</groupId>
<artifactId>splain_2.13.6</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
with the old one (by sbt):
...
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.13.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.5</version>
</dependency>
<dependency>
<groupId>com.chuusai</groupId>
<artifactId>shapeless_2.13</artifactId>
<version>2.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.zio</groupId>
<artifactId>zio_2.13</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-core_2.13</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The pom file generated by gradle has a self-referential dependency to itself. This has caused nexus publishing to fail the sanity check. My questions are:
should this be illegal? Why is gradle permitting this?
why was it generated?
Gradle has a few other problems (like the deprecation of the provided scope) but so far this is the most serious of them all.
Fixed, turns out the problem was caused by "java-test-fixtures" plugin.
Test fixture doesn't have a maven scope counterpart, so by default their dependencies are merged into compile scope dependencies when publishing. The problem disappeared once I disabled their publishing:
val javaComponent = components["java"] as AdhocComponentWithVariants
from(javaComponent)
javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }

Redis connection is failed

I'd like to work with Redis for manipulating sessions.But I get failure when running the spring boot app.So I guess that this error is coming from maven dependencies especially version conflicts.
Here is my maven dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
</dependencies>
Notice that I added two dependencies in above pom.xml which there artifactId are spring-session-data-redis and lettuce-core.These dependencies are respectively responsible for Redis connection and ensuring thread safety for session connections.
When I run the spring boot app, I get the belowed error:
APPLICATION FAILED TO START
Description:
An attempt was made to call the method org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List; but it does not exist. Its class, org.springframework.data.redis.connection.RedisConnection, is available from the following locations:
jar:file:/C:/Users/aoutir/.m2/repository/org/springframework/data/spring-data-redis/2.0.10.RELEASE/spring-data-redis-2.0.10.RELEASE.jar!/org/springframework/data/redis/connection/RedisConnection.class
It was loaded from the following location:
file:/C:/Users/aoutir/.m2/repository/org/springframework/data/spring-data-redis/2.0.10.RELEASE/spring-data-redis-2.0.10.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.redis.connection.RedisConnection
Please any help is very appreciated,thanks in advance for your reply.
I have spent a whole day to resolve the exactly same issue. And after a whole day R&D, I found the solution.
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-data-rest')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-data-redis')
implementation('org.springframework.session:spring-session-data-redis')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
testImplementation('org.springframework.boot:spring-boot-starter-test')
runtimeOnly('org.flywaydb:flyway-core')
runtimeOnly('com.h2database:h2')
// runtimeOnly('mysql:mysql-connector-java')
}
Use 'spring-boot-starter-data-redis' and 'spring-session-data-redis'.
Remove lettuse dependency as it is included in spring-boot-starter-data-redis as dependency.
Here is your dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
Simply delete the explicit version for spring-session-data-redis and go with the version from the spring boot parent pom.
If you want to change the version of spring-session-data-redis, you have to ensure that none of the transitive dependencies is managed by the parent pom. If I downgrade to version 1.3 (version 1.7 could not be found) I end up with the following version mismatch as revealed by mvn -X dependency:tree:
[ESC[1;36mDEBUGESC[m] org.springframework.session:spring-session-data-redis:jar:1.3.3.RELEASE:compile
[ESC[1;36mDEBUGESC[m] org.apache.commons:commons-pool2:jar:2.5.0:compile (version managed from 2.4.2)
[ESC[1;36mDEBUGESC[m] org.springframework.data:spring-data-redis:jar:2.0.10.RELEASE:compile (version managed from 1.7.10.RELEASE)
Please replace the dependency
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
with
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
The version management is done automatically and the started will initialize the redis cache.

when spring-rabbit dependency added to pom.xml mvn is giving exceptions

This is the code which I had added to my spring project which is not getting started when trying to run with tomcat.
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
Instead of two dependencies add only one dependency as follows.
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>

Why Missing artifact?

This is part of the pom
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.3.1</version>
</dependency>
An it is creating some files in the local repository but not the jar
those are the files created for swagger-models
m2e-lastUpdated.properties
swagger-models-1.0.1.jar.lastUpdated
swagger-models-1.0.1.pom.lastUpdated
swagger-models-1.0.1-sources.jar.lastUpdated
There is no swagger-models version 1.x. the io.swagger / swagger-models artifact was introduced in 1.5.0--you should be using 1.5.7

Deploy Microsoft Azure API jar on karaf

i am new to Maven and OSGI, can anyone please help me knowing how to deploy Microsoft Azure API jar on karaf OSGI container?
Following is pom content of my Maven project.
com.microsoft.windowsazure
microsoft-windowsazure-api
0.4.3
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.3-1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>
i have embedded dependencies like following
<Embed-Dependency>
microsoft-windowsazure-api,
commons-lang3,
commons-logging,
jackson-core-asl,
jackson-jaxrs,
jackson-mapper-asl,
jackson-xc,
javax.inject,
jaxb-impl,
jersey-client,
jersey-core,
jersey-json,
jettison,
mail
</Embed-Dependency>
When i do this it keeps showing missing dependencies for different packages. i have imported all packages (*) in pom.
download bnd.jar (bundle tool)
keep azur and bnd both jar in a directory
go to that directory and run following command
java -jar bnd.jar wrap microsoft-windowsazure-api 0.4.3.jar
tada... your bundle is ready, just deploy it and continue your work :)
Take a look at jcloud feature for Karaf it also contains some bundles for azure. I'm sure this will give you a list of bundles working.

Resources