I'm playing with the tomcat plugin for gradle and in my build/tmp/tomcatRun/work/Tomcat/localhost/myWebApp directory its empty. Is there a way for me to specify the location of my war to deploy?
I tried
[tomcatRun, tomcatRunWar]*.destinationDir= new File("$buildDir/libs").getAbsoluteFile().getPath()
and
[tomcatRun, tomcatRunWar]*.warDirectory= new File("$buildDir/libs").getAbsoluteFile().getPath()
Update
I've added the build scripts below. When I run my new tasks I've been running
gradle build integrationTest
Here is a snippet from the parent build.gradle:
buildscript {
repositories {
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = 'GitHub'
addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
}
}
dependencies {
classpath 'bmuschko:gradle-tomcat-plugin:0.9.2'
}
}
allprojects {
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
ext.springVersion = "3.1.1.RELEASE"
ext.hibernateVersion = "3.6.7.Final"
ext.mysqlVersion = "5.1.20"
ext.tomcatVersion = "7.0.26"
ext.junitVersion = "4.10"
ext.httpClientVersion = "4.2"
ext.pdfboxVersion = "1.7.1"
ext.resxWebserviceVersion = "10.4.2"
loadConfiguration()
}
and my webapps build.gradle:
apply plugin: "maven"
apply plugin: "war"
apply plugin: "tomcat"
def now = new Date()
def cssDir = new File("truexpense-web/src/main/webapp/css").getAbsoluteFile().getPath()
def minCssName = 'all-min.css'
def jsDir = new File("truexpense-web/src/main/webapp/js").getAbsoluteFile().getPath()
def minJsName = 'all-min.js'
ext.requestor = ''
ext.fromAddress = ''
ext.replyAddress = ''
ext.formattedDate = now.format('dd MMM yyy HH:mm')
ext.product = 'Truexpense'
configurations {
deployerJars
jasper
mail
}
dependencies {
//Compile time but not included dependencies
providedCompile "javax.servlet:javax.servlet-api:3.0.1"
providedCompile "org.apache.tomcat:tomcat-jdbc:$tomcatVersion"
//Compile time dependencies
compile project(":truexpense-domain")
compile project(":truexpense-repository")
compile project(":truexpense-service")
compile "org.springframework:spring-core:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.hibernate:hibernate-core:$hibernateVersion"
compile "org.hibernate:hibernate-envers:$hibernateVersion"
compile "org.hibernate:hibernate-ehcache:$hibernateVersion"
compile "org.hibernate:hibernate-validator:4.2.0.Final"
compile "commons-io:commons-io:2.3"
compile "commons-codec:commons-codec:1.6"
compile "org.springframework.security:spring-security-core:3.1.0.RELEASE"
compile "org.springframework.security:spring-security-config:3.1.0.RELEASE"
compile "org.springframework.security:spring-security-web:3.1.0.RELEASE"
compile "javax.mail:mail:1.4"
compile "mysql:mysql-connector-java:$mysqlVersion"
compile "com.google.visualization:visualization-datasource:1.0.2"
compile "org.ostermiller:utils:1.07.00"
compile "net.sf.ofx4j:ofx4j:1.4"
compile "org.jpedal:jbig2:1"
compile "org.apache.pdfbox:txp-fontbox:$pdfboxVersion"
compile "org.apache.pdfbox:txp-jempbox:$pdfboxVersion"
compile "org.apache.pdfbox:txp-pdfbox:$pdfboxVersion"
compile "taglibs:taglibs-unstandard:1"
compile "org.codehaus.jackson:jackson-mapper-asl:1.9.7"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
//Runtime only dependencies
runtime "commons-beanutils:commons-beanutils-core:1.8.3"
runtime "joda-time:joda-time:2.1"
runtime "org.springframework.security:spring-security-taglibs:3.1.0.RELEASE"
runtime "org.springframework:spring-beans:$springVersion"
runtime "org.springframework:spring-context:$springVersion"
runtime "org.springframework:spring-core:$springVersion"
runtime "org.springframework:spring-expression:$springVersion"
runtime "org.springframework:spring-instrument:$springVersion"
runtime "org.springframework:spring-instrument-tomcat:$springVersion"
runtime "org.springframework:spring-jdbc:$springVersion"
runtime "org.springframework:spring-jms:$springVersion"
runtime "org.springframework:spring-orm:$springVersion"
runtime "org.springframework:spring-oxm:$springVersion"
runtime "org.springframework:spring-tx:$springVersion"
runtime "org.springframework:spring-web:$springVersion"
runtime "org.springframework:spring-webmvc:$springVersion"
runtime ("commons-fileupload:commons-fileupload:1.2.2") {
exclude group: "javax.servlet", module: "javax.servlet-api"
exclude group: "portlet-api"
}
runtime ("javax.servlet:jstl:1.2") {
exclude group: "javax.servlet", module: "javax.servlet-api"
exclude group: "javax.servlet", module: "jsp-api"
}
//Test only dependencies
tomcat "org.apache.tomcat:tomcat-dbcp:${tomcatVersion}"
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
//Deployments
deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2"
[tomcatRun, tomcatRunWar]*.httpPort = 8090
[tomcatRun, tomcatStop]*.stopPort = 8081
[tomcatRun, tomcatStop]*.stopKey = 'stopKey'
task integrationTest(type: Test) {
include '**/*IntegrationTest.*'
doFirst {
tomcatRun.daemon = true
tomcatRun.execute()
}
doLast {
tomcatStop.execute()
}
}
test {
exclude '**/*IntegrationTest.*'
}
}
war {
baseName='truexpense'
eachFile {
if (it.name == 'login_css_include.jsp') {
it.expand(loginCSS: "login-min.css?t=${now.getTime()}")
}
else if (it.name == 'all_css_include.jsp') {
it.expand(allCSS: "all-min.css?t=${now.getTime()}")
}
else if (it.name == 'all_js_include.jsp') {
it.expand(allJS: "all-min.js?t=${now.getTime()}")
}
}
}
task deploy << { deploy() }
task minifyCSS << {
def files = fileTree(dir: "${cssDir}", includes: [
"analysis.css",
"header.css",
"footer.css",
"blocks.css",
"chosen.css",
"grids.css",
"space.css",
"dataTables.css",
"newCore.css",
"core.css",
"skin_clean.css",
"plugins.css",
"css3.css",
"jquery-ui.css",
"jquery.lightbox-0.5.css",
"jqueryFileTree.css",
"jquery.qtip.css",
"expense.css",
"report.css",
"zentab.css"
]).getFiles().sort({it.name})
concatenate("${cssDir}/all.css", files)
yuiCompressor("${cssDir}/all.css", "${cssDir}/${minCssName}")
yuiCompressor("${cssDir}/login.css", "${cssDir}/login-min.css")
}
task minifyJS << {
def files = fileTree(dir: "${jsDir}", excludes:[
'all*.js',
'jqtouch*.js'
]).getFiles().sort({it.name})
concatenate("${jsDir}/all.js", files)
yuiCompressor("${jsDir}/all.js", "${jsDir}/${minJsName}")
}
def yuiCompressor(from, to) {
ant.java(jar:"tools/yuicompressor-2.4.7.jar", fork: true, failonerror: true) {
arg(value: from)
arg(value: "-o")
arg(value: to)
}
}
def concatenate(filePath, files) {
File file = new File(filePath)
if (file.exists()) {
file.write("")
}
files.each { File f ->
file.append(f.getText() + '\n')
}
}
def deploy() {
println "Deleting ${tomcatHome}/webapps/${war.baseName}"
delete "${tomcatHome}/webapps/${war.baseName}"
println "Deleting ${tomcatHome}/work/Catalina/localhost/${war.baseName}"
delete "${tomcatHome}/work/Catalina/localhost/${war.baseName}"
println "Copying ${war.archiveName} to ${tomcatHome}/webapps"
copy {
from war.archivePath
into "${tomcatHome}/webapps"
}
}
How do you reference your applicationContext.xml in your web.xml? If you use the full path (/WEB-INF/classes/applicationContext.xml) then I'd probably change it to search for it on the classpath:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
Related
When I set an IntelliJ version as described below I have the following error
intellij {
version '2022.3'
}
A problem occurred configuring root project 'brs-plugin'.
Failed to notify project evaluation listener.
Failed to query the value of extension 'intellij' property 'version'.
> The value for the 'intellij.version' property was not specified, see:
https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-version
But if I add the equal operator have the following
intellij {
version = '2022.3'
}
Caused by: org.gradle.internal.exceptions.DefaultMultiCauseException:
Could not resolve com.jetbrains.intellij.idea:ideaIC:2022.3.
This is my full version of the build.gradle. As you can see I have added several repos, but it's not helped. Full version of the project you can found on this link
How to fix my problem? Regards
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "https://www.jetbrains.com/intellij-repository/releases"
}
maven {
url "https://www.jetbrains.com/intellij-repository/snapshots"
}
maven {
url "https://cache-redirector.jetbrains.com/intellij-dependencies"
}
}
}
plugins {
id "org.jetbrains.intellij" version "1.11.0"
id "org.jetbrains.grammarkit" version "2020.1"
}
configurations {
configurations.compileOnly.setCanBeResolved(true)
}
group 'com.interfaced'
version = '0.2.7'
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.intellij'
sourceSets {
all {
java.srcDirs += ['src/main/gen']
kotlin.srcDirs += ['src/main/kotlin']
resources.srcDirs = ['src/main/resources']
}
}
intellij {
version = '2022.3'
}
grammarKit {
jflexRelease = '1.7.0-2'
}
repositories {
mavenCentral()
maven {
url "https://cache-redirector.jetbrains.com/intellij-dependencies"
}
}
dependencies {
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.7.22'
implementation files('jars/grammar-kit.jar')
implementation group: 'junit', name: 'junit', version: '4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.6.0'
}
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
def GENERATE_GROUP = 'Generate'
task setConfiguration() {
configurations.compileOnly.setCanBeResolved(true)
}
task generateLexer(type: GenerateLexer) {
source = "src/main/grammar/BrightScript.flex"
targetDir = "src/main/gen/com/interfaced/brs/lang/lexer"
targetClass = "_BrsLexer"
skeleton = "src/main/grammar/idea-flex.skeleton"
purgeOldFiles = true
description = 'Generate Lexer Java sources for BrightScript'
group = GENERATE_GROUP
}
task generateParser(type: GenerateParser) {
source = "src/main/grammar/BrightScript.bnf"
targetRoot = 'src/main/gen'
pathToParser = 'src/main/gen/com/interfaced/brs/lang/BrsParser.java'
pathToPsiRoot = 'src/main/gen/com/interfaced/brs/lang/psi'
purgeOldFiles = true
description = 'Generate Parser Java sources for BrightScript'
group = GENERATE_GROUP
// patch up to date check
outputs.upToDateWhen { false }
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
compileKotlin.dependsOn(setConfiguration, generateLexer, generateParser)
I'm very new to gradle and javaFx.
I'm working on a gradle project (not mine) and I need to import SwingFXUtils to make some operations.
Importing it into the java file:
import javafx.embed.swing.SwingFXUtils;
cause the error: "Cannot resolve symbold SwingFXUtils".
I tried to add it to java-modules.java file
requires javafx.embed.swing;
but it is not recognized and I'm having the error message: "Module not found:javafx.embed.swing"
then, I updated my build.gradle for the missing module: like this:
plugins {
id 'application'
id 'org.beryx.jlink' version '2.19.0'
id 'com.google.osdetector' version '1.6.2'
}
repositories {
flatDir {
dirs "libs"
}
jcenter()
maven { url "https://maven.geotoolkit.org/" }
mavenCentral()
}
ext {
toolName = 'my project'
toolVersion = '1.0.0'
mainModuleName = 'com.myproject'
mainClassName = 'com.myproject.DcTool'
jfxVersion = '14.0.1'
pdfboxVersion = '2.0.27'
platform = osdetector.os == 'osx'?'mac':osdetector.os =='windows'?'win':osdetector.os
fixWayland = platform == 'mac' ? '' : platform == 'win' ? '' : '-Djdk.gtk.version=2'
}
version = "$toolVersion"
// Project dependencies.
dependencies {
compileOnly "org.jetbrains:annotations:19.0.0"
implementation "org.openjfx:javafx-base:$jfxVersion:$platform"
implementation "org.openjfx:javafx-graphics:$jfxVersion:$platform"
implementation "org.openjfx:javafx-controls:$jfxVersion:$platform"
implementation "org.openjfx:javafx-fxml:$jfxVersion:$platform"
implementation "com.fazecast:jSerialComm:2.6.2"
implementation "ch.qos.logback:logback-classic:1.3.0-alpha4"
implementation "de.skuzzle:semantic-version:2.1.0"
implementation "info.picocli:picocli:4.3.2"
annotationProcessor "info.picocli:picocli-codegen:4.3.2"
implementation "org.apache.pdfbox:pdfbox:${pdfboxVersion}"
implementation "org.apache.pdfbox:preflight:${pdfboxVersion}"
implementation "com.fasterxml.jackson.jr:jackson-jr-objects:2.11.0"
implementation group: 'org.openjfx', name: 'javafx-swing', version: '11-ea+24'
}
java {
modularity.inferModulePath = true
}
application {
mainModule.set("$mainModuleName")
mainClass.set("$mainClassName")
applicationDefaultJvmArgs = [
"-Dfile.encoding=UTF-8",
]
}
tasks.withType(JavaCompile) {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath
]
classpath = files()
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_14
options.encoding = "UTF-8"
options.javaModuleVersion.set("$toolVersion")
options.javaModuleMainClass.set("$mainClassName")
}
run {
doFirst {
jvmArgs = [
"--module-path", classpath.asPath,
'--patch-module', "$mainModuleName=" + files(sourceSets.main.output.resourcesDir).asPath,
"--module", "$mainModuleName/$mainClassName"
]
jvmArgs += application.applicationDefaultJvmArgs
classpath = files()
}
doLast {
args = []
}
}
jar {
manifest {
attributes(
'Main-Class': "$mainClassName"
)
}
}
JAVA_HOME=$(/usr/libexec/java_home)
jlink {
moduleName.set("$mainModuleName")
mainClass.set("$mainClassName")
addOptions(
'--bind-services',
'--no-header-files',
'--no-man-pages',
'--strip-debug',
'--compress', '2')
launcher {
name = "$toolName"
jvmArgs += application.applicationDefaultJvmArgs
}
}
I also tried to download jars of SwingFx and add them in a "libs" folder into the project but I have no result and compiler doesn't find modules I need.
What can I do to make it find this module?
Thank you for your help.
What could be missing in this build.gradle file that prevents the publishToMavenLocal not to copy files to the .m2 folder?
The script does have the 'maven-publish' plugin.
buildscript {
ext.kotlinVersion = '1.3.10'
ext.dokkaVersion = '0.9.17'
repositories { mavenLocal() }
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
}
}
plugins {
id 'com.github.hierynomus.license' version '0.15.0'
id 'io.codearte.nexus-staging' version '0.11.0'
id 'maven-publish'
}
group = 'org.jetbrains.xodus'
version = hasProperty('xodusVersion') ? project.xodusVersion : ''
def isSnapshot = version.endsWith('SNAPSHOT')
def isDailyBuild = hasProperty('dailyBuild') ? project.dailyBuild : false
def mavenPublishUrl = hasProperty('mavenPublishUrl') ? project.mavenPublishUrl : ''
def mavenPublishUsername = hasProperty('mavenPublishUsername') ? project.mavenPublishUsername : ''
def mavenPublishPassword = hasProperty('mavenPublishPassword') ? project.mavenPublishPassword : ''
def signingKeyId = hasProperty('signingKeyId') ? project.signingKeyId : ''
def signingPassword = hasProperty('signingPassword') ? project.signingPassword : ''
def signingSecretKeyRingFile = hasProperty('signingSecretKeyRingFile') ? project.signingSecretKeyRingFile : '../key.gpg'
static def shouldDeploy(project) {
return project.version.length() > 0 && !(project.name in ['benchmarks', 'samples'])
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5.1'
}
defaultTasks 'assemble'
// Use nexus-staging-plugin to workaround https://issues.sonatype.org/browse/OSSRH-5454
nexusStaging {
username = mavenPublishUsername
password = mavenPublishPassword
delayBetweenRetriesInMillis = 30000
stagingProfileId = "89ee7caa6631c4"
}
subprojects {
apply plugin: 'license'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'org.jetbrains.dokka'
sourceCompatibility = 1.7
compileJava.options.encoding = 'UTF-8'
group = rootProject.group
version = rootProject.version
archivesBaseName = rootProject.name + '-' + project.name
license {
header rootProject.file('license/copyright.ftl')
strictCheck true
ext.inceptionYear = 2010
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.owner = 'JetBrains s.r.o.'
include "**/*.kt"
include "**/*.java"
mapping {
kt = 'JAVADOC_STYLE'
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
}
// tests for most of sub-projects run with database encryption turned on
if (!(project.name in ['benchmarks', 'compress', 'crypto', 'openAPI', 'samples', 'utils'])) {
test {
systemProperty 'exodus.cipherId', 'jetbrains.exodus.crypto.streamciphers.ChaChaStreamCipherProvider'
systemProperty 'exodus.cipherKey', '000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f'
systemProperty 'exodus.cipherBasicIV', '314159262718281828'
// uncomment the following line to run tests in-memory
//systemProperty 'exodus.log.readerWriterProvider', 'jetbrains.exodus.io.inMemory.MemoryDataReaderWriterProvider'
}
dependencies {
testCompile project(':crypto')
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
jar {
manifest {
attributes 'Implementation-Title': archivesBaseName, 'Implementation-Version': version
}
}
test {
minHeapSize = '1g'
maxHeapSize = '1g'
//jvmArgs = ['-ea', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=2808']
//testLogging.showStandardStreams = true
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
duplicatesStrategy 'exclude'
includeEmptyDirs false
from javadoc.destinationDir
}
javadoc.failOnError = false
// work around for Java 8 javadoc which is too strict
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task sourceJar(type: Jar) {
classifier = 'sources'
duplicatesStrategy 'exclude'
includeEmptyDirs false
from project.sourceSets.main.java
from project.sourceSets.main.kotlin
}
// configuring projects with Kotlin sources
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile 'io.github.microutils:kotlin-logging:1.5.4'
}
compileKotlin {
kotlinOptions {
languageVersion = '1.2'
apiVersion = '1.2'
}
}
compileTestKotlin {
kotlinOptions {
languageVersion = '1.2'
apiVersion = '1.2'
}
}
dokka {
jdkVersion = 7
packageOptions {
reportUndocumented = false
}
}
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
javadocJar {
dependsOn dokkaJavadoc
from dokkaJavadoc.outputDirectory
}
artifacts {
archives jar, javadocJar, sourceJar
}
if (!isSnapshot && signingKeyId.length() > 0) {
ext.'signing.keyId' = signingKeyId
ext.'signing.password' = signingPassword
ext.'signing.secretKeyRingFile' = signingSecretKeyRingFile
}
afterEvaluate { project ->
if (shouldDeploy(project)) {
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
if (isDailyBuild) {
repository(url: "https://api.bintray.com/maven/jetbrains/xodus/" + archivesBaseName + "/;publish=1") {
authentication(userName: mavenPublishUsername, password: mavenPublishPassword)
}
} else {
repository(url: mavenPublishUrl) {
authentication(userName: mavenPublishUsername, password: mavenPublishPassword)
}
}
pom.project {
name 'Xodus'
description 'Xodus is pure Java transactional schema-less embedded database'
packaging 'jar'
url 'https://github.com/JetBrains/xodus'
scm {
url 'https://github.com/JetBrains/xodus'
connection 'scm:git:https://github.com/JetBrains/xodus.git'
developerConnection 'scm:git:https://github.com/JetBrains/xodus.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'JetBrains'
name 'JetBrains Team'
organization 'JetBrains s.r.o'
organizationUrl 'http://www.jetbrains.com'
}
}
}
}
}
}
signing {
required { !isSnapshot && signingKeyId.length() > 0 && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}
}
}
}
Your build does not configure any publications, hence the publishToMavenLocal task is a noop:
$ ./gradlew --console=verbose publishToMavenLocal
> Task :publishToMavenLocal UP-TO-DATE
BUILD SUCCESSFUL in 0s
When you configure a publication as in this example …
task buildMyArtifact(type: Zip) {
// TODO using the build script as a sample file here; use whatever makes
// sense for your project
from 'build.gradle'
archiveBaseName = 'whateverNameInBuildDir'
destinationDirectory = buildDir
}
publishing {
publications {
myPublication(MavenPublication) {
artifact buildMyArtifact
groupId 'com.example'
artifactId 'my-module'
version '1.0.0'
}
}
}
… then the publishToMavenLocal task installs the publication into the local Maven repository:
$ ./gradlew --console=verbose publishToMavenLocal
> Task :buildMyArtifact
> Task :generatePomFileForMyPublicationPublication
> Task :publishMyPublicationPublicationToMavenLocal
> Task :publishToMavenLocal
BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
$ tree ~/.m2/repository/com/example/my-module/
/home/chriki/.m2/repository/com/example/my-module/
├── 1.0.0
│ ├── my-module-1.0.0.pom
│ └── my-module-1.0.0.zip
└── maven-metadata-local.xml
1 directory, 3 files
I have a bunch of projects whose configuration should be based on a template (only name changes, different dependencies). To do that I defined a parent project called "server" that holds that common configuration part in subprojects section.
group 'com.kbhit.orangebox.server'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE"
classpath 'com.bmuschko:gradle-docker-plugin:3.0.1'
}
}
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
ext.defineArtifact = { Map artifact ->
ext {
projectName = "$artifact.name"
projectVersion = '1.0.0'
artifactName = "$artifact.name-artifact.version.jar"
dockerBuildDir = "$buildDir/docker/"
}
springBoot {
executable = true
}
docker {
url = 'http://192.168.99.101:2376'
certPath = file(System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default")
}
jar {
baseName = projectName
version = projectVersion
}
task createDockerfile(type: Dockerfile) {
destFile = file("$buildDir/docker/Dockerfile")
from 'java:8u91'
exposePort 8080
copyFile "$buildDir/docker/app.jar", '/app/app.jar'
workingDir '/app'
defaultCommand 'java', '-jar', 'app.jar'
}
task buildImage(type: DockerBuildImage, group: 'docker') {
dependsOn 'bootRepackage', 'createDockerfile'
inputDir = file("$buildDir/docker")
doFirst {
copy {
from "$buildDir/libs"
into dockerBuildDir
include artifactName
rename artifactName, 'app.jar'
}
}
}
task createContainer(type: DockerCreateContainer, group: 'docker') {
dependsOn buildImage
targetImageId { buildImage.getImageId() }
containerName projectName
}
task startContainer(type: DockerStartContainer, group: 'docker') {
dependsOn createContainer
targetContainerId { createContainer.getContainerId() }
}
task stopContainer(type: DockerStopContainer, group: 'docker') {
targetContainerId { createContainer.getContainerId() }
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'com.bmuschko.docker-remote-api'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven {
url('http://localhost:10001/content/groups/public/')
}
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0'
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
}
afterEvaluate {
task startServer() {
dependsOn subprojects.startContainer
}
}
Here's the configuration of one of the modules:
defineArtifact(name: 'orb-api-gateway', version: '1.0.0')
dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-zuul'
compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile 'org.springframework.cloud:spring-cloud-starter-config'
testCompile group: 'com.jayway.restassured', name: 'rest-assured', version: '2.9.0'
}
The problem is that:
Child projects need to "inject" their properties "up" before those are requested in task definitions, eg. buildImage task - I'd use $dockerBuildDir variable which should be defined in defineArtifact method based on the arguments provided by the child module.
Parent module must have access to tasks created for child modules. See startServer task at the bottom.
Of course this won't work as at the time no task are created. If I were to fix this I would have to make server project evaluate after it's children but then I would not be able to define defineArtifact method before children request it. How to solve this problem?
I have this when I execute "gradle tasks --all"
assemble - Assembles the outputs of this project. [jar]
toneserver:assemble - Assembles the outputs of this project. [toneserver:jar, webserver:jar]
toneserver:copyJars
toneserver:zip
webserver:assemble - Assembles the outputs of this project. [webserver:jar]
webserver:versionFile
webserver:zip
What I really really don't get is I have toneserver:zip depending on toneserver:jar and I have webserver:zip depending on webserver:jar but this tasks --all is not showing those dependencies. Why is this? and how to get it to truly show the dependencies?
My full gradle file is below(and yes I need to move the apply plugin stuff still out of all projects into subprojects section and other
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
//override gradle's default output directory(build) on every project as it conflicts with
//our build script called build causing failures.
buildDir = 'output'
repositories {
mavenCentral()
}
if (project.hasProperty('myVersion')) {
project.ext.realVersion = project.myVersion
project.version = project.myVersion
} else {
project.ext.realVersion = 'Developer-Build'
project.version = 'Developer-Build'
}
test {
beforeTest { desc ->
println "Executing test ${desc.name} [${desc.className}]"
}
}
task hello << { task -> println "I'm $task.project.name" }
build << { task -> println "MASTER: I'm building now" } //"building with classpath=$sourceSets.main.compileClasspath.files"
}
project(':webserver') {
//play does not follow maven/gradle standard of src/main/java and src/test/java :( :(
//so we override the directories here...(we should put test in the sourceSets.test.java.srcDirs instead)
sourceSets.main{
java.srcDirs = ['app', 'test']
resources.srcDirs = ['app']
}
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: 'play-*.jar')
}
//MOVE this into allprojects to be run by both toneserver and webserver to put a file there...
task versionFile() << {
File f = new File('webserver/output/version');
f.mkdirs()
File v = new File(f, 'version'+project.ext.realVersion)
println('output version file='+v.getAbsolutePath())
v.createNewFile()
}
task zip(type: Zip) {
archiveName 'dashboard-'+project.version+'.zip'
from('output/version') {
into('webserver')
}
from('..') {
exclude '**/*.pyc'
exclude '**/*.class'
exclude '**/samples-and-tests/**'
exclude '**/play-1.2.4/documentation/**'
exclude 'webserver/conf/logback.xml'
include 'webserver/run*.sh'
include 'webserver/lib/**'
include 'webserver/app/**'
include 'webserver/conf/**'
include 'webserver/play-1.2.4/**'
include 'webserver/public/**'
}
rename 'prod.(.*)', '$1'
}
zip.dependsOn('versionFile')
zip.dependsOn('jar')
assemble.dependsOn('zip')
//playframework has it's own generation of .classpath and .project fils so do not
//overwrite their versions. NEED to call "play.bat eclipsify" here...
task eclipse(overwrite: true) << {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "*** WINDOWS "
def result = exec {
commandLine 'cmd', '/c', 'play-1.2.4\\play.bat eclipsify'
}
} else {
println "*** NOT WINDOWS "
def result = exec {
commandLine './play-1.2.4/play eclipsify'
}
}
}
}
project(':toneserver') {
project.ext.genLibDir = file('output/thirdpartylibs')
configurations {
all*.exclude module: 'log4j'
}
dependencies {
compile 'com.google.inject:guice:3.0'
compile 'com.google.protobuf:protobuf-java:2.4.1'
//weird, why is their maven not working(we drop it in the directory instead)...
//compile 'org.asteriskjava:asterisk-java:1.0.0.M3'
//to be erased as soon as we get the chance...(we should try this NOW and see if it is needed anymore)
compile 'commons-configuration:commons-configuration:1.8'
compile 'org.bouncycastle:bcpg-jdk16:1.46'
compile project(':webserver')
//gradle is not sucking in transitive dependencies when they exist in another project so we suck them
//in ourselves here...
compile fileTree(dir: '../webserver/play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: '../webserver/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework', include: 'play-*.jar')
compile 'org.bouncycastle:bcpg-jdk16:1.46'
testCompile 'junit:junit:4.11'
}
task generateSources {
project.ext.outputDir = file("$buildDir/generated-src")
outputDir.exists() || outputDir.mkdirs()
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "*** WINDOWS "
def result = exec {
commandLine 'cmd', '/c', '..\\tools\\protoc\\protoc.exe', '--java_out=output\\generated-src', 'src\\schemas\\agentbridge.proto'
}
} else {
throw new RuntimeException("DARN, protoc only works on windows :( :( right now")
}
}
compileJava.dependsOn("generateSources")
sourceSets {
main {
java {
srcDir 'output/generated-src'
}
}
}
tasks.eclipse.dependsOn("generateSources")
task copyJars(type: Copy) {
from(configurations.compile) {}
into genLibDir
}
task initconfig(type:Copy) {
from('src/staging/toneserver') {
include '**/*'
}
into 'output/staging'
}
task zip(type: Zip) {
archiveName 'toneserver-'+project.version+'.zip'
from('src/staging') {
include 'toneserver/**'
}
from('output/thirdpartylibs') {
into('toneserver/lib')
}
from('output/version') {
into('webserver')
}
}
zip.dependsOn('copyJars')
zip.dependsOn('jar')
assemble.dependsOn('zip')
}
//overwrite the eclipse target so that no .classpath ends up in stserver directory
task eclipse(overwrite: true) {
}
gradle tasks --all shows all tasks, but only first-level task dependencies. I agree that it would be useful to have a way to visualize the whole task graph, but it's not something that Gradle currently offers out-of-the-box.