Gradle - two plugins have the same root block name, which resolve conflict - gradle

I'm trying to use 2 different plugins that have the same root block name, what's causing conflict and error in the build process.
The 2 plugins are defined in the build.gradle :
plugins {
id 'java'
id 'application'
id 'com.benjaminsproule.swagger' version '1.0.8'
id 'org.detoeuf.swagger-codegen' version '1.7.4'
}
apply plugin: 'org.detoeuf.swagger-codegen'
version '1.0-SNAPSHOT'
mainClassName = 'ServiceMain'
swagger {
apiSource {
springmvc = true
locations = ['com.google.charger']
schemes = ['https']
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
}
swaggerDirectory = 'swagger'
swaggerFileName = 'charger-service-api-swagger'
attachSwaggerArtifact = true
}
}
swagger {
inputSpec = "${project.projectDir}/swagger/charger-service-api-swagger.json"
outputDir = file("${project.projectDir}/../charger-server-api-client/")
lang = 'java'
additionalProperties = [
'invokerPackage' : 'com.google.ev.charger.server',
'modelPackage' : 'com.google.ev.charger.server.model',
'apiPackage' : 'com.google.ev.charger.server.api',
'dateLibrary' : 'joda',
'groupId' : 'com.google.ev',
'artifactId' : 'charger.server',
'artifactVersion' : '1.0.0',
'hideGenerationTimestamp': 'true'
]
}
sourceSets {
swagger {
java {
srcDir file("${project.buildDir.path}/swagger/src/main/java")
}
}
}
As you can see both plugins starts with the same block name (swagger),
Is there any way to specify the plugin for each configuration?

I ended up using code to resolve this issue,
I am using a property called "CreateSwagger" that I'm passing (either from CLI or from gradle.properties file) to separate the 2 scenarios.
The issue I had is that the plugins {} block is not allowed inside the if that evaluates the condition so I needed to use the "old" legacy plugin " apply plugin:"
This is how my build.gradle ended up looking:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.benjaminsproule:swagger-gradle-plugin:1.0.8"
classpath "gradle.plugin.org.detoeuf:swagger-codegen-plugin:1.7.4"
}
}
plugins {
id 'java'
id 'application'
id 'maven'
}
if(project.properties.containsKey('CreateSwagger')){
apply plugin: "com.benjaminsproule.swagger"
} else {
apply plugin: 'org.detoeuf.swagger-codegen'
}
version '1.0-SNAPSHOT'
mainClassName = 'EVChargerRestServiceMain'
if(project.properties.containsKey('CreateSwagger')){
swagger {
apiSource {
springmvc = true
locations = ['com.google.charger']
schemes = ['https']
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
}
swaggerDirectory = 'swagger'
swaggerFileName = 'charger-service-api-swagger'
attachSwaggerArtifact = true
}
}
}
else {
swagger {
inputSpec = "${project.projectDir}/swagger/charger-service-api-swagger.json"
outputDir = file("${project.projectDir}/../charger-server-api-client/")
lang = 'java'
additionalProperties = [
'invokerPackage' : 'com.google.ev.charger.server',
'modelPackage' : 'com.google.ev.charger.server.model',
'apiPackage' : 'com.google.ev.charger.server.api',
'dateLibrary' : 'joda',
'groupId' : 'com.google.ev',
'artifactId' : 'charger.server',
'artifactVersion' : '1.0.0',
'hideGenerationTimestamp': 'true'
]
}
}

Related

Gradle startScript - Could not find or load main class

After looking into various answers in SO regarding the topic (which did not help me), I am raising a new question
I am new to Gradle, using version 1.0
Working with application plugin
it looks pretty simple
but I am facing difficulty running the start script
when I run the start script for windows, it says "Error: Cannot load or find main class"
Whereas with gradle run it runs successfully
here is my gradle file:
build.gradle
apply plugin: 'java'
apply plugin: 'application'
def properties = new Properties()
file('build.properties').withReader { properties.load(it) }
properties.each { key, value -> project.ext.set(key, value) }
task wrapper(type: Wrapper) {
gradleVersion = '1.0'
}
mainClassName = 'org.sample.Main'
defaultTasks 'clean', 'build'
repositories {
....
}
jar {
manifest {
def manifestClasspath = configurations.runtime.collect {
it.getName() }\
.join(' ')
attributes(
'Manifest-Version' : 1.0,
'Specification-Title' : project.ext.specTitle,
'Sepcification-Version' : project.ext.specVersion,
'Specification-Vendor' : project.ext.specVendor,
'Implementation-Title' : project.ext.implTitle,
'Implementation-Version': project.ext.implVersion,
'Implementation-Vendor' : project.ext.specVendor,
'Main-Class' : 'org.sample.Main',
'Class-Path' : manifestClasspath
)
}
}

Gradle cannot find project (project with path $ cannot be found)

This project (example) depends on a project defined in the parent directory. It is not part of the parent directory project's build at all. However, Gradle never finds a project in any of my folders with projects in them. The parent directory contains a multiplatform multiproject library project for libGDX. I cannot call project() and find one in ANY directory so far...
FAILURE: Build failed with an exception.
* Where:
Settings file '/home/athenacadence/git/gdx-complextext/example/settings.gradle' line: 2
* What went wrong:
A problem occurred evaluating settings 'example'.
> Project with path '/../html' could not be found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
CONFIGURE FAILED
Total time: 0.124 secs
gdx-complextext/example/settings.gradle
include 'desktop', 'android', 'ios', 'html', 'core', 'ios-moe'
includeBuild(project("/../html"))
gdx-complextext/build.gradle
ext {
GROUPID = 'com.athenaeumapps.gdxcomplextext'
VERSION = '0.0.1-SNAPSHOT'
}
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
maven { url uri(System.getenv("INTEL_MULTI_OS_ENGINE_HOME") + "/gradle") }
}
dependencies {
classpath 'com.goharsha:gwt-opentype:0.1-SNAPSHOT'
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0'
classpath group: 'org.multi-os-engine', name: 'moe-gradle', version: '1.1.+'
}
}
allprojects {
apply plugin: "eclipse"
ext {
appName = 'gdx-complextext'
gdxVersion = '1.9.6'
roboVMVersion = '2.2.0'
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
group = GROUPID
version = VERSION
}
project(":android") {
configurations {
custom
compile.extendsFrom custom
}
eclipse {
project {
name = appName + "-android"
}
}
dependencies {
compile project(':core')
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
}
}
project(":core") {
apply plugin: 'java'
apply from: '../publish.gradle'
configurations {
custom
compile.extendsFrom custom
}
eclipse {
project {
name = appName + "-core"
}
}
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
}
}
project(":desktop") {
apply plugin: 'java'
apply from: '../publish.gradle'
configurations {
custom
compile.extendsFrom custom
}
eclipse {
project {
name = appName + "-desktop"
}
}
dependencies {
compile project(':core')
}
}
project(":html") {
apply plugin: 'java'
apply from: '../publish.gradle'
configurations {
custom
compile.extendsFrom custom
}
eclipse {
project {
name = appName + "-html"
}
}
dependencies {
compile project(':core')
}
dependencies {
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
}
}
project(":ios") {
apply plugin: 'java'
apply plugin: 'robovm'
apply from: '../publish.gradle'
configurations {
custom
compile.extendsFrom custom
}
eclipse {
project {
name = appName + "-ios"
}
}
dependencies {
compile project(':core')
compile "com.mobidevelop.robovm:robovm-rt:${roboVMVersion}"
compile "com.mobidevelop.robovm:robovm-cocoatouch:${roboVMVersion}"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
}
}
project(":ios-moe") {
apply plugin: 'java'
apply plugin: 'moe'
apply from: '../publish.gradle'
configurations {
custom
compile.extendsFrom custom
natives
}
eclipse {
project {
name = appName + "-ios-moe"
}
}
dependencies {
compile project(':core')
compile "com.badlogicgames.gdx:gdx-backend-moe:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
}
}
EDIT
Upon trying just includeBuild, I get this:
includeBuild("${rootProject.projectDir}/../html")
Please try to use another way to obtain a project location using rootProject.projectDir then add ../html, also according to documentation there's no need to wrap into project e.g. use only includeBuild like below:
includeBuild("${rootProject.projectDir}/../html")
Another example can be found here

Using a plugin from separate Gradle Script

I have been using a plugin to generate some documentation. When I place the code for it inside the build.gradle for each package it works perfectly.
However instead of having this plugin in multiple build.gradle files I want to place it in a separate gradle script to keep everything more central.
However when i do this I get an error of :
Plugin with id 'com.benjaminsproule.swagger' not found.
Despite the code being the exact same as when it is in the build.gradle file.
Here is the code to import the plugin and use it:
buildscript {
repositories {
maven {url "http://jcenter.bintray.com"}
}
dependencies {
classpath 'com.benjaminsproule:swagger-gradle-plugin:0.0.8'
}
}
apply plugin: 'com.benjaminsproule.swagger'
swagger {
apiSource {
springmvc = false
locations = ['package1']
info {
title = 'Package 1'
version = 'v1'
description = 'Documentation for Package 1'
}
swaggerDirectory = "${project.rootDir}/reports/Package1"
}
apiSource {
springmvc = false
locations = ['package2']
info {
title = 'Package 2'
version = 'v1'
description = 'Documentation for Package 2'
}
swaggerDirectory = "${project.rootDir}/reports/Package2"
}
}
So I want to move this all from build.gradle to a file called swagger.gradle, is this possible?
I also run the plugin using:
gradle swagger
Figured out a solution myself, might be useful for anyone else who runs into this problem.
I created a Swagger.gradle file which contained the buildscript and the build.gradle then called in the plugin.
For Apply plugin I had to called directly the main class of the plugin.
Swagger.gradle
buildscript {
repositories {
maven {url "http://jcenter.bintray.com"}
}
dependencies {
classpath 'com.benjaminsproule:swagger-gradle-plugin:0.0.8'
}
}
apply plugin: com.benjaminsproule.swagger.gradleplugin.GradleSwaggerPlugin
Build.gradle
apply from: "/scripts/Swagger.gradle"
swagger {
apiSource {
springmvc = false
locations = ['package1']
info {
title = 'Package 1'
version = 'v1'
description = 'Documentation for Package 1'
}
swaggerDirectory = "${project.rootDir}/reports/Package1"
}
apiSource {
springmvc = false
locations = ['package2']
info {
title = 'Package 2'
version = 'v1'
description = 'Documentation for Package 2'
}
swaggerDirectory = "${project.rootDir}/reports/Package2"
}
}
Credit to this Blog: http://mrhaki.blogspot.co.uk/2015/10/gradle-goodness-apply-external-script.html

Using gradle with a local artifactory repository

I am new to gradle and artifactory both.
What I want to accomplish is to have separate projects with each project creating a jar file that will be used by other projects in the same application.
For example, I have a utility project that has, wait for it..., utility classes. I then have a services project with the, that's right, services. The services use the utilities to accomplish some of their work.
I've spent several hours and finally have the utility project committing to my artifactory repository using this script:
buildscript {
repositories {
mavenLocal()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
apply plugin: 'java'
apply plugin: "com.jfrog.artifactory"
archivesBaseName = 'heavyweight-software-util'
repositories {
mavenCentral()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
}
dependencies {
testCompile("junit:junit:4.11")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
artifactory {
contextUrl = "http://picard:8080/artifactory" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
username = 'xxxx'
password = "xxxx"
maven = false
ivy {
ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
mavenCompatible = false
}
}
}
resolve {
repository {
repoKey = 'libs-release'
username = 'xxxx'
password = "xxxx"
maven = false
ivy {
ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
mavenCompatible = false
}
}
}
}
When I run this I get the following:
C:\Users\thom\git\utility\Utility>gradle artifactoryPublish
[buildinfo] Not using buildInfo properties file for this build.
:artifactoryPublish
Deploying build descriptor to: http://picard:8080/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://picard:8080/a
rtifactory/webapp/builds/Utility/1436807848026/2015-07-13T13:17:27.704-0400/
BUILD SUCCESSFUL
Total time: 6.874 secs
Hurrah! Or, so I thought.
Because as soon as this wrapped up, I thought, "Now how do I get this file out." I looked at the links above and they're there, but I can't see how this is a jar file. I tried looking at libs-release-local in my tree browser, but it shows 0 artifacts.
Here's what I found under build info JSON under the build:
{
"version" : "1.0.1",
"name" : "Utility",
"number" : "1436807848026",
"type" : "GRADLE",
"buildAgent" : {
"name" : "Gradle",
"version" : "2.4"
},
"agent" : {
"name" : "Gradle",
"version" : "2.4"
},
"started" : "2015-07-13T13:17:27.704-0400",
"durationMillis" : 474,
"principal" : "thom",
"artifactoryPrincipal" : "admin",
"licenseControl" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoDiscover" : false,
"licenseViolationsRecipientsList" : "",
"scopesList" : ""
},
"buildRetention" : {
"count" : -1,
"deleteBuildArtifacts" : true,
"buildNumbersNotToBeDiscarded" : [ ]
},
"governance" : {
"blackDuckProperties" : {
"runChecks" : false,
"includePublishedArtifacts" : false,
"autoCreateMissingComponentRequests" : false,
"autoDiscardStaleComponentRequests" : false
}
}
}
I've googled and researched and can't seem to figure out how to make use of the jar file I have committed to my repository.
OK, after reading: https://docs.gradle.org/current/userguide/publishing_ivy.html and https://docs.gradle.org/current/userguide/artifact_management.html and finally, http://forums.jfrog.org/405-HTTP-method-PUT-not-supported-td5786632.html I have pieced together an answer to my question. I have attached the build script that performs the upload properly...
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
apply plugin: 'java'
apply plugin: 'ivy-publish'
archivesBaseName = 'heavyweight-software-util'
repositories {
mavenCentral()
ivy {
url 'http://picard:8080/artifactory/plugins-release'
}
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
testCompile("junit:junit:4.11")
}
publishing {
publications {
ivy(IvyPublication) {
organisation 'com.heavyweightsoftware'
module 'heavyweight-util'
revision '1.0'
from components.java
}
}
repositories {
ivy {
url 'http://picard:8080/artifactory/libs-release-local'
credentials {
username "xxxxx"
password "xxxxx"
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
Now that I know that the publication is working correctly, I should be able to use the repository without issue.

QueryDSL, spring-boot & Gradle

I was hoping to bring querydsl into my spring-boot project via gradle. Despite finding a couple of examples online, none of them actually work for me because of issues with dependencies (I think). According to the QueryDSL support forum, gradle is not supported yet. But I was wondering with all the gradle & spring-boot being created if someone has managed to make it work yet?
Here is my build.gradle:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC4")
}
}
repositories {
mavenCentral()
maven { url: "http://repo.spring.io/libs-snapshot" }
// maven { url: "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.0.0.RC5")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC5")
compile("org.springframework:spring-orm:4.0.0.RC1")
compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("org.thymeleaf:thymeleaf-spring4")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
// this line fails
querydslapt "com.mysema.querydsl:querydsl-apt:3.3.2"
testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
sourceSets {
main {
generated {
java {
srcDirs = ['src/main/generated']
}
}
java {
srcDirs = []
}
groovy {
srcDirs = ['src/main/groovy', 'src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
output.resourcesDir = "build/classes/main"
}
test {
java {
srcDirs = []
}
groovy {
srcDirs = ['src/test/groovy', 'src/test/java']
}
resources {
srcDirs = ['src/test/resources']
}
output.resourcesDir = "build/classes/test"
}
}
configurations {
// not really sure what this is, I see it in examples but not in documentation
querydslapt
}
task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
source = sourceSets.main.java
classpath = configurations.compile + configurations.querydslapt
options.compilerArgs = [
"-proc:only",
"-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
]
destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}
compileJava {
dependsOn generateQueryDSL
source generateQueryDSL.destinationDir
}
compileGeneratedJava {
dependsOn generateQueryDSL
options.warnings = false
classpath += sourceSets.main.runtimeClasspath
}
clean {
delete sourceSets.generated.java.srcDirs
}
idea {
module {
sourceDirs += file('src/main/generated')
}
}
But gradle fails with:
Could not find method querydslapt() for arguments [com.mysema.querydsl:querydsl-apt:3.3.2]
I have tried changing the querydsl-apt version to earlier ones but I get the same error.
Working configuration for Spring Boot 1.3.5 and supported QueryDSL, tested with gradle 2.14.
ext {
queryDslVersion = '3.6.3'
javaGeneratedSources = file("$buildDir/generated-sources/java")
}
compileJava {
doFirst {
javaGeneratedSources.mkdirs()
}
options.compilerArgs += [
'-parameters', '-s', javaGeneratedSources
]
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile "com.mysema.querydsl:querydsl-jpa:$queryDslVersion"
compileOnly "com.mysema.querydsl:querydsl-apt:$queryDslVersion:jpa"
}
Complete project source code: spring-boot-querydsl
You probably need to do at least 2 things:
Declare the "querydslapt" configuration before you use it
Add querydsl-jpa (or whatever flavours you need) to your "compile" configuration.
Then you will have the classpath set up, but the apt bit will not do anything without some more configuration (as you found no doubt from the querydsl support forum). The apt but is used to generate some code that you then need to compile and use in your application code (the "Q*" classes corresponding to your domain objects). You could drive that from a build task in gradle I imagine (it only has to run once for every change in the domain objects).

Resources