Why does the liberty-gradle-plugin fail on CompileJSP? - gradle

I am trying to get the liberty-gradle-plugin to run. I created a minimal build.gradle and it still fails:
plugins {
id 'io.openliberty.tools.gradle.Liberty' version '3.0'
id 'war'
}
repositories {
jcenter()
}
dependencies {
providedCompile group: 'javax', name: 'javaee-api', version: '8.0.1'
libertyRuntime group: 'com.ibm.websphere.appserver.runtime', name: 'openliberty-runtime', version: '[20.0.0.2,)'
}
It fails with:
An exception occurred applying plugin request [id: 'io.openliberty.tools.gradle.Liberty', version: '3.0']
> Failed to apply plugin [id 'io.openliberty.tools.gradle.Liberty']
> Could not create task ':compileJSP'.
> Could not create task of type 'CompileJSPTask'.
> Could not generate a decorated class for class io.openliberty.tools.gradle.tasks.CompileJSPTask.
> io/openliberty/tools/ant/ServerTask
I have no intention to use JSP. So is there a way to fix this? Or to disbale the JSP part?

It looks like it is a bug: https://github.com/OpenLiberty/ci.gradle/issues/441
The using the buildscript version works for now.

Related

Groovy compilation fails: Unable to load class 'org.grails.io.support.Resource'

I'm developing a JavaFX application written in Groovy and using Gradle. When I started up my application in IntelliJ recently, it seemingly from out of the blue started failing to compile with the error:
Unable to load class 'org.grails.io.support.Resource'.
This is an unexpected error. Please file a bug containing the idea.log file.
This is from running the "run" gradle task.
This is my build file:
plugins {
id 'groovy'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
group 'redacted'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
maven { url "https://download.java.net/maven/2/"}
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
// Logback log-annotation
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
// https://mvnrepository.com/artifact/org.controlsfx/controlsfx
implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.1.0'
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
// ---- GPars concurrency lib ----
// https://mvnrepository.com/artifact/org.codehaus.gpars/gpars
implementation group: 'org.codehaus.gpars', name: 'gpars', version: '1.2.1'
// ---- Jira Client ----
// https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-app
implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-app', version: '5.2.0'
// https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-api
implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-api', version: '5.2.0'
// ---- Misc ----
// https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv
implementation group: 'io.github.cdimascio', name: 'java-dotenv', version: '5.2.2'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation group: 'org.jsoup', name: 'jsoup', version: '1.14.3'
// ---- REST ----
// https://mvnrepository.com/artifact/org.springframework/spring-web
implementation group: 'org.springframework', name: 'spring-web', version: '3.0.2.RELEASE'
// https://mvnrepository.com/artifact/org.grails/grails-datastore-rest-client
implementation group: 'org.grails', name: 'grails-datastore-rest-client', version: '6.1.9.RELEASE'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
implementation group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// https://mvnrepository.com/artifact/net.dongliu/requests
implementation group: 'net.dongliu', name: 'requests', version: '5.0.8'
// https://mvnrepository.com/artifact/io.jsondb/jsondb-core
implementation group: 'io.jsondb', name: 'jsondb-core', version: '1.0.115-j11'
}
test {
useJUnitPlatform()
}
javafx {
modules = ['javafx.controls', 'javafx.fxml']
version = '11.0.2'
}
mainClassName = 'redacted'
Has anyone seen this before? The things I've tried:
Invalidating caches in IntelliJ
Clean + Rebuild
Rollback code to a point I know compiled.
Update gradlew to use gradle 7.4
UPDATE
I seem to have found the culprit. My company has recently changed stuff related to how we build our projects, which requires using a init.gradle file in the .gradle/ folder, which contains some standard repository definitions. This is the content (with company repositories redacted):
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
buildscript {
repositories {
maven {
url "https://<redacted>"
credentials {
username mavenUser
password mavenPassword
}
}
}
}
repositories {
mavenLocal()
maven {
url "https://<redacted>"
credentials {
username mavenUser
password mavenPassword
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
url "https://<redacted>"
}
}
}
}
Removing it fixed the problem for the project in question, but will obviously not work for all the other work related projects. So the question remains...how does this cause such an error?
UPDATE 2
I have not exactly found the source of the error, but it seems to have something to do with the repositories being declared in a wrong way. To fix this, one can call clear() in the project build.gradle file at the top of the repositories definition, effectively ignoring what's declared in init.gradle. So, just update the repositories {} clause to:
repositories {
clear() // This is needed in order for init.gradle to not cause errors
mavenCentral()
maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
maven { url "https://download.java.net/maven/2/"}
}
I have not exactly found the source of the error, but it seems to have something to do with the repositories being declared in a wrong way. To fix this, one can call clear() in the project build.gradle file at the top of the repositories definition, effectively ignoring what's declared in init.gradle. So, just update the repositories closure to:
repositories {
clear() // This is needed in order for init.gradle to not cause errors
mavenCentral()
maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
maven { url "https://download.java.net/maven/2/"}
}

Why does my Gradle build fail with a "Plugin [id: 'org.flywaydb.enterprise.flyway', version: '6.5.0'] was not found" error?

When I run gradle clean build I get the build error message:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\meno.varghese\git\imc-modulemanager-poc\imc-poc\build.gradle' line: 5
* What went wrong:
Plugin [id: 'org.flywaydb.enterprise.flyway', version: '6.5.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.flywaydb.enterprise.flyway:org.flywaydb.enterprise.flyway.gradle.plugin:6.5.0')
Searched in the following repositories:
MavenLocal(file:/C:/Users/meno.varghese/.m2/repository)
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I don't understand why the flyway plugin cannot be found. How can I fix it?
Here's my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.0.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "org.flywaydb.enterprise.flyway" version '6.5.0'
}
apply plugin: "eclipse"
group = 'com.imc.poc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'org.javassist', name: 'javassist', version: '3.27.0-GA'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.808'
}
flyway {
//url = 'jdbc:mysql://localhost:3306/imc_poc?user=root&password=password'
// driver = 'org.postgresql.Driver'
url = 'jdbc:mysql://imc-modulemanager.cwouijqzv1sr.ap-south-1.rds.amazonaws.com:3306'
user = 'admin'
password = 'Indegene12345'
schemas=['moduledb']
}
With reference to the official Flyway Gradle Plugin documentation page
plugins {
id "org.flywaydb.flyway.enterprise" version "6.5.0"
}
Your plugin declaration in your gradle.build
id "org.flywaydb.enterprise.flyway" version '6.5.0'
is simply wrong, and thus cannot be found.

How to enable Allure history using Gradle and Junit5?

I know I could copy the history directory from allure-reports to a generated allure-results, and then do allure generate to get the history to show up, but I am looking for a way to achieve this with the built-in functionality in allure-gradle.
Currently, I run ./gradlew clean test, then ./gradlew allureReport, and this gives me a fresh html report with no history or reruns. I have noticed that the test task deletes the entire allure-reports directory and then re-makes and re-populates it.
Here is my build.gradle:
buildscript {
repositories {
mavenLocal()
jcenter()
}
}
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'java'
id 'eclipse'
// Allure reporter
id 'io.qameta.allure' version '2.8.1'
}
repositories {
mavenCentral()
jcenter()
}
def allureVersion = "2.13.1"
allure {
autoconfigure = true
version = allureVersion
useJUnit5 {
version = '2.0-BETA10'
}
downloadLink = "https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.1/allure-commandline-2.13.1.zip"
}
test {
useJUnitPlatform() {
includeEngines 'junit-jupiter'
}
ignoreFailures = true
}
dependencies {
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.0'
compile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.6.0'
// Needed as a workaround for JUnit 5 not failing tests that stopped due to an error message. The fix is in eclipse 4.10
compile group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.6.0'
compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.13.1'
compile group: 'io.qameta.allure', name: 'allure-java-commons', version: '2.13.1'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
}
I have also tried specifying the results and reports directories to be outside of the build directory, like this:
allure {
autoconfigure = true
version = allureVersion
resultsDir = file('../../allure-results')
reportDir = file('../../allure-report')
...
}
This allows the allure-results folder to keep the previous report, which show up as retries (not quite right), but history still doesn't work.
I have solved this problem by adding at the running test script these lines( I have some tests scuites)
call gradlew test -PsuiteFile=YOUR_TEST_SUITE.xml
mkdir allure-results\history
xcopy build\allure-results\* allure-results\history
allure serve allure-results\history
So I have added folder allure-results\history to keep all results

Could not find method provided() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.1.0}]

I am getting the following error:
Could not find method provided() for arguments [{group=javax.servlet,
name=javax.servlet-api, version=3.1.0}]
I have tried several different ways and found people with similar issues but with no avail. I added the below dependency but
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
If I remove the javax.servlet I am back to the orginal error:
Could not find method providedCompile() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.1.0}]
update 1:
new error after adding:
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
error
> Could not find javax.servlet:servlet-api:3.1.0.
Searched in the following locations:
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.pom
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.jar
Required by:
project :
UPDATE:
I added:
allProjects {
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
jcenter()
mavenCentral()
version = '0.0.1-SNAPSHOT'
group = 'com.lidl.digital.ecom.ratings'
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
}
And now the error is:
What went wrong: A problem occurred evaluating root project 'product-rating-parent'.
Could not set unknown property 'sourceCompatibility' for object of type org.gradle.api.internal.initialization.DefaultScriptHandler.
I have seen this error prior to fixing this posted question so I am not sure if it is fixed. When I hover over anything in the gradle file it says cannot resolve 'whatever I hover over'
It seems, that you have added your dependency in the wrong place. Dependecies are declared within dependencies block as follows
dependencies {
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
But in your case it's declared within repositories.
There is a difference between what you report as added and your exception:
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
The above is correct, and exists in Maven Central.
However, your error:
Could not find javax.servlet:servlet-api:3.1.0.
Searched in the following locations:
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.pom
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.jar
Required by:
project :
It clearly indicates a typo somewhere in the project where the dependency module name is missing the javax. part in front of servlet-api.
So you must have somewhere code like:
dependencies {
compileOnly group: 'javax.servlet', name: 'servlet-api', version:'3.1.0'
}
Notice the missing javax. in the name attribute.

custom gradle plugin causes: Cannot configure the 'publishing' extension

I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with error message :
FAILURE: Build failed with an exception.
* Where:
Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating root project 'integtest'.
> Cannot configure the 'publishing' extension after it has been accessed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.6 secs
Here is the build.gradle file.
buildscript {
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
dependencies {
classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'MyCustomPlugin' // WHen this line is moved above maven-publish, build works fine.
// add jar name and version
jar.archiveName='lrgemaas_small_deploy_3n.jar'
group = 'com.mycom.proj.test'
version = '1.0.3'
dependencies {
compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1'
compile group: 'eaas.platform', name: 'registry-client', version: '0.1'
compile configurations.lrgConfig // This configuration is added by MyCustomPlugin
compile configurations.webdriver // This configuration is added by MyCustomPlugin
}
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
publishing {
publications {
myPublicationName(MavenPublication) {
artifactId 'lrgemaas_small_deploy_3n'
artifact jar.archivePath
}
}
repositories {
maven {
url = "${artifactory_contextUrl}/${artifactory_repoName}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
// workflow for build
defaultTasks 'clean','build','publish'
PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.
Simply replacing:
publishing {
publications {
...
}
}
with following:
publishing.publications {
...
}
worked for me!
Gradle is brittle regarding the order of the plugins. There is a discussion about this exact issue at
https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460
"Cool, so this is what happens.
DefaultPublishingExtension which is backing the 'publishing {}' block is a DeferredConfigurable. It's a mechanism that allows to register a configuration block to be executed when an extension is accessed. Unfortunately sometimes it causes unexpected behaviour if you access this kind of extension unawares. This is exactly the case when for example you try to get all the properties of a project (as the release plugin does here: https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper.groovy#L230"
FYI, I use a dynamic version and found that I had to define version prior to apply of my plugins. Probably because java or maven-publish sets the publication details upon application.
I upgraded gradle version from 2.1 to 2.12 and it solved this problem, fwiw.

Resources