I have this project structure:
-root-project
-settings.gradle
-build.gradle
-subProjectA(spring-boot)
-build.gradle
-subprojectB(spring-boot)
-build.gradle
-subprojectC(spring-boot)
-build.gradle
-commonProject(java library)
-build.gradle
It is simple of my root settings.gradle:
rootProject.name = 'root-project'
include 'subProjectA'
include 'subprojectB'
include 'subprojectC'
include 'commonProject'
It is my root project build.gradle:
group = 'my.domain'
version = '0.0.1-SNAPSHOT'
ext {
springBootVersion = '2.1.3.RELEASE'
cxfVersion = '3.2.7'
uuidGeneratorVersion = '3.1.5'
commonLang3Version = '3.7'
encacheVersion = '2.6.11'
logstashVersion = '5.2'
}
And in each subProject, I have build.gradle file with these plugins:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'
I have duplicate plugins and spring-boot dependency in each subModule and I want to move it to a common(root) file. But I don't understand how can I do it.
In the root build.gradle file you can apply common plugins or other configurations like common tasks, sourceCompatibility & targetCompatibility, manifest info, test configs, etc.. using the subprojects block as shown below.
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
manifest {
attributes (
'Built-By' : System.properties['user.name'],
'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
}
// Other Configs
}
Related
I'm using Gradle 6.7 for a project and I'm using IntelliJ. When writing Gradle files or when running inspections, I keep getting this error.
"Cannot assign 'String' to 'Publication'".
Based on the Gradle docs and all the examples, it seems as though my configuration is correct but I'm unable to resolve these warnings.
import org.gradle.api.tasks.testing.logging.TestLogEvent
buildscript {
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
jcenter()
}
dependencies {
classpath "org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:1.0.1"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.8"
classpath "net.ltgt.gradle:gradle-nullaway-plugin:0.2"
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.5"
}
}
}
apply plugin: 'java'
apply plugin: 'scalaStyle'
apply plugin: 'scala'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'java-library'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'net.ltgt.nullaway'
apply plugin: "com.dorongold.task-tree"
apply plugin: "jacoco"
group 'com.mridang'
version '0.0.2'
...
...
publishing {
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mridang/myrepo")
credentials(PasswordCredentials)
}
}
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact scaladocJar
pom {
name = 'myproject'
description = 'Foo'
url = 'https://github.com/mridang/myrepo'
issueManagement {
system = "Github"
url = "https://github.com/mridang/myrepo/issues"
}
}
}
}
}
Here's a screenshot that better illustrates the issue:
It is false positive inspection warning. You can vote for this issue in tracker: IDEA-162281.
I am creating a library which doesn't have a main class at all. The library uses Spring which has application plugin which is looking for mainClassName. I added mainClassName with null, but I am looking for a better solution. I googled around and found that adding bootJar.enabled = false will not look for mainClassName but it is not helping. Can someone help me out?
ext {
springBootVersion = '2.2.1.RELEASE'
satelliteVersion = '2.12.3'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE') {
exclude group: 'org.slf4j'
exclude module: 'spring-boot-starter-log4j'
}
}
}
plugins {
id 'java'
id 'groovy'
id 'idea'
id 'distribution'
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenLocal()
mavenCentral()
}
bootJar.enabled = false
apply plugin: 'maven-publish'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
version = System.getenv('CI') == 'drone' ? "1.0.${System.getenv('DRONE_BUILD_NUMBER')}" : "local"
tasks.validateYaml.enabled = false
dependencies {
implementation "org.springframework.boot:spring-boot-starter-mail:${springBootVersion}"
implementation group: 'com.google.guava', name: 'guava', version: '18.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact tasks.sourcesJar
}
}
}
configurations.all {
exclude module: 'spring-boot-starter-logging'
exclude group: 'ch.qos.logback'
exclude module: 'logback-access-spring-boot-starter'
}
I get the following error
A problem was found with the configuration of task ':startScripts' (type 'CreateStartScripts').
> No value has been specified for property 'mainClassName'.
Adding
startScripts.enabled = false
bootJar.enabled = false
distTar.enabled = false
solved my issue.Thanks
Would like to add my answer in 2022 since the accepted one didnt work for me. Removing the springboot plugin did the trick however.
// id 'org.springframework.boot' version '2.6.1'
// id 'io.spring.dependency-management' version '1.0.11.RELEASE'
On the root level project, I have a build.gradle with the following:
plugins {
id "org.sonarqube" version "2.2.1"
id 'net.saliman.cobertura' version '2.4.0'
}
apply plugin: 'groovy'
apply plugin: 'cobertura'
cobertura {
coverageFormats = ['html', 'xml']
coverageReportDir = new File("$projectDir/reports/cobertura")
rootProject.subprojects.each {
coverageReportDir = new File("$it.name/reports/cobertura")
}
}
But when I run ./gradlew cobertura it will only generate the reports/cobertura directory on the root project.
What's going on here?
Try
configure(allprojects) {
plugins {
id "org.sonarqube" version "2.2.1"
id 'net.saliman.cobertura' version '2.4.0'
}
apply plugin: 'groovy'
apply plugin: 'cobertura'
cobertura {
coverageFormats = ['html', 'xml']
coverageReportDir = new File("$projectDir/reports/cobertura")
rootProject.subprojects.each {
coverageReportDir = new File("$it.name/reports/cobertura")
}
}
}
le 'C:\Users\naresh.vatsal\workspace_spring_jan14\SpringMvcUsingGradle\build.gradle' line: 28
ent wrong:
m occurred evaluating root project 'SpringMvcUsingGradle'.
not find method compile() for arguments [org.springframework:spring-context:4.0.0.RELEASE] on org.gradle.api.internal.artifacts.dsl.dependencies.Default
cyHandler_Decorated#434c4af3.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat-base'
apply plugin: 'com.bmuschko.cargo'
ext.tomcatVersion = '7.0.67'
ext.cargoVersion = '1.1.3'
sourceCompatibility = 1.7
buildscript
{
repositories {
maven {
url "https://plugins.grdev.net/m2/"
mavenCentral()
}
}
dependencies {
classpath "com.bmuschko:gradle-tomcat-plugin:2.2.4"
classpath 'com.bmuschko:gradle-cargo-plugin:2.2'
}
dependencies {
compile 'org.springframework:spring-context:4.0.0.RELEASE'
compile 'org.springframework:spring-webmvc:4.0.0.RELEASE'
compile 'org.aspectj:aspectjrt:1.7.4'
compile 'javax.inject:javax.inject:1'
compile 'javax.servlet:jstl:1.2'
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'org.slf4j:jcl-over-slf4j:1.7.5'
compile 'org.slf4j:slf4j-log4j12:1.7.5'
compile 'log4j:log4j:1.2.15'
testCompile 'junit:junit:4.7'
}
}
cargo {
containerId = 'tomcat7x'
port = 8080
local {
homeDir = file('C:/mdi/soft/apache-tomcat-7.0.67')
output = file('C:/mdi/soft/apache-tomcat-7.0.67/output.log')
}
}
war {
version = '' `enter code here`
}
i get a strange behaviour (at least for me :D) when I switch from the gradle file located in https://spring.io/guides/gs/serving-web-content/ to a multi project gradle file setup.
build.gradle in root directory
//Applied to all projects.
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
group = 'de.test.platform'
version = '0.1'
}
subprojects {
//Currently all subprojects are also java projects. If this changes we
//need to move it into the corresponding projects
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
idea {
module {
downloadSources = true
downloadJavadoc = false
}
}
}
idea {
project {
jdkName = '1.8'
languageLevel = '1.8'
}
}
build.gradle in sub directory frontend (thus sub project called :frontend)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'spring-boot'
jar {
baseName = 'crowdio-frontend'
version = '0.1.0'
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
when I run gradle bootRun and navigate to http://localhost:8080/greeting as in the tutorial i get a infinite loop error. If i change the template from greeting.html to hello.html and return hello instead of greeting in the controller greeting() action i get an 404 Error.
The template is stored in project_root/frontend/src/main/resources/templates/greeting.html
It seems like that for whatever Reason spring boot can decide on thymeleaf with the exact structure of the gradle build file like in the tutorial. However if you switch to a multi project setup you need to add
compile("org.thymeleaf:thymeleaf-spring4")
as a dependency.