I'm trying to get a better understanding of what is possible to do with gradle plugins. I've done some reading on https://docs.gradle.org/current/userguide/custom_plugins.html, but
I do not feel like it answers my questions.
Right now we have several projects that are built into ear files with the ear-plugin.
However, for all our ear-projects we have a bunch of other config that we at the moment have in a company_ear.gradle file
that we apply in the build.gradle file of our ear-projects.
example of our company_ear.gradle:
allprojects {
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
}
apply plugin: 'ear'
ear {
appDirName 'application'
rename('([^-]*)(.*)(.war)', '$1$3')
rename('([^-]*)(.*)(.jar)', '$1$3')
}
task devDeploy (type: Copy, dependsOn: assemble) {
//code to do local deploy of ear
}
// More custom stuff that should apply to all ear-projects
So my question is, is it possible to move this to a custom gradle plugin so I can just do "apply plugin: company-ear"? I understand how to do the "devDeploy" task
in a plugin but I can not understand how I would fix the allProjects, apply plugin: 'ear', and ear-block in a custom plugin.
Related
I need to setup a Gradle multiproject java build with a fixed build folder.
The structure needs to be like this:
--projectRoot/
----build/ (shared for both subprojects)
----javaApp1/
----javaApp2/
After the build there should be two shell scripts for starting the applications:
--projectRoot/
----build/
------javaApp1
------javaApp2
------libs/
--------javaApp1.jar
--------javaApp2.jar
so far my settings.gradle is in the projectRoot:
rootProject.name = 'com.example.project'
include 'javaApp1'
include 'javaApp2'
and the build.gradle in the projectRoot:
allprojects {
repositories {
jcenter()
}
buildDir = new File(projectDir, "../build")
}
subprojects {
group 'com.example.project'
apply plugin: 'java'
apply plugin: 'application'
dependencies {
testImplementation 'junit:junit:4.12'
}
}
with this I'm already able to build from the projectRoot and with gradle installDist I get the wanted shell scripts in projectRoot/build/install/javaApp1/bin/javaApp1 but not in the build folder directly.
So to recap: the shell scripts should end up in projectRoot/build.
I have a gradle spring java project setup, after weeks of it working, Idea suddenly thinks it is an android project, keeps asking me for Android SDK, after deleting .gradle and out/ folders and setting JDK in settings, it compiles and starts, but doesn't copy application.properties file that is required to run the app. Tried restarting, deleting .gradle, .idea, and any other output folder that I could find, but it seems like the only solution that temporarily helps is to clone the repository to a new folder. My suspicion is that I have something in my gradle file that tricks idea to think it's android, but couldn't find anything.
My build.gradle
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
ext {
springVersion = "4.3.12.RELEASE"
springBootVersion = '2.1.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.ebean:ebean-gradle-plugin:11.34.1")
}
}
apply plugin: SpringBootPlugin
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.ebean'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-websocket:${springBootVersion}")
implementation("org.mindrot:jbcrypt:0.3m")
implementation('io.jsonwebtoken:jjwt-api:0.10.5')
runtime "io.jsonwebtoken:jjwt-impl:0.10.5", "io.jsonwebtoken:jjwt-jackson:0.10.5"
implementation("org.springframework:spring-jdbc:${springVersion}")
implementation("org.apache.logging.log4j:log4j-core:2.11.1")
implementation("org.postgresql:postgresql:42.2.5")
implementation("org.apache.tomcat:tomcat-jdbc:9.0.8")
implementation("io.ebean:ebean:11.36.1")
implementation("io.ebean:ebean-agent:11.11.1")
implementation("io.ebean:ebean-spring-txn:11.10.4")
testImplementation("junit:junit:'4.+")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
Clean IDE project specific files and regenerate them with
./gradlew cleanIdea idea
Then try to import project again.
After a lot of searching, it was the last option to raise it here! In eclipse, I am designing such project structure using Gradle, as shown below...
Algorithms //Parent Project
-SubModuleCore //Child Project for common utilities & dependencies
-build.gradle
-SubModuleOne //Child project for any operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-SubModuleTwo //Child project for another operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-build.gradle
-settings.gradle
Services //Stand-Alone project
-build.gradle //Here I want to add 'Algorithms' as a single dependency
-settings.gradle
Project structures are same in eclipse work-space as shown above. I am able to generate individual .jar of Algorithms project. So the problem is I want to add this Algorithms project as a single dependency in project Services like compile project(':Algorithms'). But eclipse just saying 'shut-up!'. I don't want to publish it somewhere like maven central / jitpack etc. instead I want to do it locally. I'm trying this way...
Services/build.gradle
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
project.webAppDirName = 'WebContent'
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
compile project(':Algorithms')
}
Services/settings.gradle
rootProject.name = 'Services'
include 'Algorithms'
project(':Algorithms').projectDir = new File(settingsDir, '../Algorithms')
Algorithms/build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
buildscript {
dependencies {
repositories {
jcenter()
mavenCentral()
}
}
}
repositories {
jcenter()
mavenCentral()
}
}
subprojects.each { subproject ->
evaluationDependsOn(subproject.path)
}
jar.dependsOn subprojects.tasks['classes']
jar {
baseName = 'algorithms'
subprojects.each { subproject ->
from subproject.sourceSets.main.output.classesDir
}
from files('resources/log4j2.xml')
from files('resources/application.properties')
}
Algorithms/settings.gradle
rootProject.name = 'Algorithms'
include ':SubModuleCore', ':SubModuleOne', ':SubModuleTwo'
I tried several solutions from SO, still not succeeded. Somebody please help me, I got stuck badly here. It seems I am very close to this, but don't know what is missing!
Thanks
You can use the includeBuild feature.
Declare the included build in Services/settings.gradle
rootProject.name='Services'
includeBuild '../Algorithms'
and then express the dependency using
compile "${project.group}:${project.name}"
where project group and name the one from the Algorithms project.
Is there a gradle plugin to package Java Webstart (JWS) applications, similar to what Maven webstart plugin does? I need to automate at least the following tasks:
jnlp descriptor generation based on an existing template, automatic adding project dependencies;
jar signing based on the files described on jnlp file or project dependencies;
As of Aug 2016, the answer is "no".
There is a plugin under development per #Jake's answer. But there is no turn key solution. You'll have to do the work yourself to create a webstart app in Gradle... either with your own custom solution or by contributing to the plugin mentioned until it works for you.
Here's the plugin direct link: https://github.com/tschulte/gradle-jnlp-plugin
Found the following link outside of Stack Overflow and looks like it does some of what you are looking for but not all. Hopefully this gets you closer to what you need...
This is an old post, but answering anyway.
I could configure gradle-jnlp-plugin.
Steps:
-Create an empty folder.
-Create src folder with Java code. I used the sample AccessibleScrollDemo.
-Copy keystore.ks from examples or create your own using genkey task in plug-in.
-Create build.gradle with following configuration.
The plug-in has examples of various options for jnlp task.
-Run plug-in task using gradle (v2.4 or more).
gradle createWebstartDir
-This will create the jnlp file under build directory, and also jars in build/lib.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.gliderpilot.gradle.jnlp:gradle-jnlp-plugin:+'
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'de.gliderpilot.jnlp'
group = 'misc'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenCentral()
}
mainClassName = 'misc.AccessibleScrollDemo'
sourceSets {
main.java.srcDir "src"
}
dependencies {
runtime('log4j:log4j:1.2.17') {
exclude group: 'ant', module: 'ant-nodeps'
exclude group: 'ant', module: 'ant-junit'
exclude group: 'ant-contrib', module: 'ant-contrib'
}
runtime 'org.slf4j:slf4j-log4j12:1.7.21'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
jnlp {
useVersions = false
usePack200 = false
withXml {
information {
title project.name
vendor project.group ?: project.name
}
security {
'all-permissions'()
}
}
signJarParams = [keystore: 'keystore.ks', alias: 'myalias', storepass: 'mystorepass']
}
compileGroovy.enabled = false
afterEvaluate {
// prevent ClassCastException
project.version = project.version.toString()
}
}
I think the Gradle JNLP Plugin currently registered in the Gradle Plugins directory may be the project for which you're looking.
Tobias Schulte's Gradle JNLP Plugin ( tschulte/gradle-jnlp-plugin on GitHub ) was striving for this about a year ago, but the new plugin is both registered in the Gradle Plugin site and looks to be under much more active development.
We are trying to setup a multi project build.
We have 2 projects:
1) PlayerManager
2) Shared
our project compiles and all the tests succeed when we run the gradle.test task
Problem is when we try to run the project on the tomcat from whithin eclipse we get class not found error for all the files in the Shared project.
Here is our gradle.build files:
PlayerManager (root)
=======================
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'
apply plugin: 'eclipse'
apply from: 'dependencies.gradle'
apply from: 'xmlHandler.gradle'
apply plugin: 'base'
dependsOn(":NGShared:NGShared")
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
runtime 'javax.servlet:jstl:1.1.2'
}
/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''
task cleanAndBuild(dependsOn: ['clean', 'assemble'])
assemble.mustRunAfter clean
tasks.withType(Test) {
testLogging {
events 'passed'
}
}
task testSanity(type: Test, dependsOn: testClasses) {
exclude '*/TimeBaseTest*'
}
Shared(sub project)
=======================
apply plugin: 'java'
apply plugin: 'eclipse'
apply from: 'dependencies.gradle'
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
settings.gradle
include ":NGShared:NGShared"
======================================================
Our path for the project is:
/NGPlayerManager/
/NGPlayerManager/NGShared/NGShared
Any ideas why ?
Thanks
Have you tried to run 'gradle eclipseClean' and then 'gradle eclipse' in order for gradle to regenerate all internal eclipse config files? If you don't do this, Eclipse will not automatically regenerate its configuration and will not include your child projects into the .ear or .war package