Gradle custom plugin: how to add custom dependency - java

I've read a lot of information about this issue, but no luck.
I writing a custom plugin. My plugins use external dependency (GSON).
My plugin: https://pastebin.com/FBG0zVed
group = 'se.thinkcode.gradle'
version = '1.0.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'maven'
sourceCompatibility = 1.8
dependencies {
compile gradleApi()
compile 'com.google.code.gson:gson:2.8.0'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
mavenLocal()
}
// try to add GSON to plugin dependencies
project.dependencies.ext.pluginDeps = {
project.fileTree("C:\\Users\\user\\Downloads")
}
dependencies {
compile pluginDeps()
}
// try to add GSON to plugin dependencies
project.configurations.compile.allDependencies;
// try to add GSON to plugin dependencies
project.buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "net.saliman:gradle-cobertura-plugin:1.1.2"
classpath 'com.google.code.gson:gson:2.8.0'
}
}
When I apply my plugin to another project I get an error:
LOG info level: https://pastebin.com/raw/7q6KQ97m
Debug: https://pastebin.com/raw/Jn9MZXbm
How I can correctly add the dependency to my plugin?

Related

gradle not able to detect module

I have a multimodule project. there is 2 modules:
- server module
- domain module
in the build.gradle of the domain module I put :
group = 'com.xxx.yyyy.zzz'
version = '1.0.0-SNAPSHOT'
and the server module imports the domain module as follow :
dependencies {
compile group: 'com.xxx.yyyy.zzz', name: 'domain', version: '1.0.0-SNAPSHOT'
...
}
howerver he is not able to detect it!
the jar is published to the maven m2 repo and I am able to see it. and i am using mavenLocal to get dependecies from the m2
repositories {
mavenLocal()
mavenCentral()
}
I deleted the gradle cache, stopped the gradle daemon without success!
Any idea ?
the build.gradle of the server module:
group = 'com.xxx.yyy.zzz'
version = '1.0.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: "org.springframework.boot"
apply plugin: "net.ltgt.apt"
apply plugin: "maven"
apply plugin: 'base'
apply plugin: 'maven-publish'
dependencies {
compile group: 'com.xxx.yyy.zzz', name: 'domaine', version: '1.0.0-SNAPSHOT'
// other dependecies ......
}
the build.gradle of the domain module:
group = 'com.desjardins.experiencecredit.gestiondemandes'
version = '1.0.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: "maven"
apply plugin: 'base'
apply plugin: 'maven-publish'
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenrepo)
}
}
}
jar.finalizedBy uploadArchives
the settings.gradle of the main project :
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'XXX'
include 'server'
include 'domaine'
If you have multiple modules in the same project, you should instead declare the dependencies using the project object:
settings.gradle at root project level
rootProject.name = 'my-application'
include 'server'
include 'domain'
Then define the build files - root project build.gradle, server module build.gradle and domain module build.gradle.
In the server module's build.gradle, declare the dependency as follows:
dependencies {
compile project(':domain')
...
}
Refer: https://guides.gradle.org/creating-multi-project-builds/

How to set up Spring boot with submodules in gradle

So I'm just playing (experimenting) with gradle and spring-boot.
When I follow the hello world I easily get the project running which kind of makes me happy.
Now I'd like to have a structured project; For this I'm using Intellij Community (not sure if relevant). I have the following structure.
/Project
- build.gradle
- settings.gradle (only includes Services)
/Project/Services/
- build.gradle
- settings.gradle (only includes MyService)
/Project/Services/MyServices
- build.gradle
Now I can share some of my build.gradle files but I"m trying random things I find on the internet. My problem is that the spring boot classes are not available at MyService. The following directory structure inside the Myservice is standard Java (/src/main/java )
I'm trying to put the dependencies & versions in my main build.gradle if possible. Can someone point out what I'm doing wrong.
Currently I've only used gradle for simple android development work.
/Project/build.gradle
group 'nl.msegers.project'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
/Project/Services/build.gradle
group 'nl.msegers.project.services'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
}
}
/Project/Services/MyService/build.gradle
group 'nl.msegers.project.services.myservice'
version parent.version
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'Navigation'
version = parent.version
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
To have every project to inherit the dependencies from the root, you could use the allprojects script block on your root project like:
allprojects {
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.+'
...
}
}
I've been scouring the web for an hour or so to get a structure like this working. In the meanwhile I've rebuild my project from scratch as well (Though I did not have much code anyway).
My code currently allows simple Spring boot sub projects without too much redundant configuration, and they can pretty easily compile the Libraries project, however this can use some work.
What I've got now is a structure like this.
/Project
/Project/Libraries
/Project/Libraries/Models
/Project/Services/
/Project/Services/Service
With the only notable build.gradle files (others are nearly empty):
/Project/Services/
group 'nl.msegers.project.services'
version parent.version
buildscript {
ext {
springBootVersion = "1.5.2.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
buildscript {
ext {
springBootVersion = "1.5.2.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile project(':Libraries:Models')
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '3.1'
}
}
/Project/Services/MyService
group 'nl.msegers.project.services.myservice'
version parent.version
jar {
baseName = 'myservice'
version = parent.version
}
repositories {
mavenCentral()
}

Java gradle no service of type styled text output factory available in project scope service

When I build a project in console I have no service of type styled text output factory available in project scope service. I have also a file pom.xml .I don't know what I do it wrong
This is my build.gradle :
import java.sql.Wrapper
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
maven { url "http://repo.spring.io/libs-milestone" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'springboot'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("javax.servlet:jstl:1.2")
runtime("mysql:mysql-connector-java")
compile("org.springframework.boot:spring-boot-starter-jdbc")
// https://mvnrepository.com/artifact/javax.el/el-api
compile group: 'javax.el', name: 'el-api', version: '2.2.1-b04'
compile ("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I believe the problem is a function of the versions of Gradle and Spring's dependency-management-plugin that are in use.
See the original report from the Spring guys in this Bug in Gradle 2.14-rc1 - No service of type StyledTextOutputFactory report. Gradle moved the StyledTextOutputFactory to an internal package at some point (for the 3.0 release), which broke dependency-management-plugin 0.5.x.
This dependency-management-plugin issue details their making changes to address this in their 0.6.0 release.
I see your build script references Gradle 2.3...but I'm wondering if that is accurate.
I think it boils down to either use Gradle 2.x with dependency-management-plugin 0.5.x or use Gradle 3.x with dependency-management-plugin 0.6.x.
Good luck.

Adding unit test to JavaFXPorts project in NetBeans - issue with Retrolambda

I found some help in this question. So I know that I must use JDK7 in order for unit testing to work.. So I came up with a build sript like this:
buildscript
{
repositories
{
jcenter()
}
dependencies
{
classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
}
}
retrolambda.oldjdk = 'C:/Program Files/Java/jdk1.7.0_79'
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'java'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
jcenter()
}
dependencies
{
testCompile 'junit:junit:4.12'
}
mainClassName = 'AppMain'
jfxmobile
{
javafxportsVersion = '8.60.7'
android
{
applicationPackage = 'com.somename.someapplication'
androidSdk = 'C:/Program Files (x86)/Android/android-sdk' //
}
}
But i keep getting this exception:
Could not get unknown property 'retrolambda' for root project
Any ideas as to how I can fix this?
You have to apply the jfxmobile plugin first, which in turn will add the retrolambda dependency. Then you can configure the retrolambda oldJdk variable.
(Pay attention for the camelCase spelling)
buildscript
{
repositories
{
jcenter()
}
dependencies
{
classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'java'
retrolambda.oldJdk = 'C:/Program Files/Java/jdk1.7.0_79'

Gradle build condition

I'm trying to make build configuration of multimodule project.
My goal is to have configuration, which will build war-file and deploy it to Tomcat.
My project contains four subprojects. There are:
api-common
api-school
api-spo
api-odo
I'd like to have war with all of modules or just some of them (api-common must always be in war)
I've main build.gradle where I configure cargo plugin
apply plugin: 'idea'
apply plugin: 'com.bmuschko.cargo'
allprojects{
apply plugin: 'java'
group = 'ru.dnevnik.enrollment'
version = '2.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.1'
}
}
cargo {
containerId = 'tomcat7x'
deployable {
context = 'api'
file = file('enrollment-api\\build\\libs\\enrollment-api-1.0.war') //todo: bad practice
}
}
Enrollment-api project has build.gradle file as
apply plugin: 'war'
configurations {
full
odo
spo
school
}
dependencies {
compile project(':enrollment-api-common')
odo project(':enrollment-api-odo')
school project(':enrollment-api-school')
spo project(':enrollment-api-spo')
}
I don't understand how to use configurations to run for example
gradle cargoDeployRemote {someFlag}
to achive my goal

Categories