The Grails delete method doesn't seem to work.
I wondered if something was wrong.
I couldn't solve it myself.
I would be happy if you could help me.
I am a Japanese who is not good at English. I'm sorry if I make a mistake in English. X(
I referred to the tutorial site.
https://koji-k.github.io/grails-tutorial/tutorials/todo-application/delete.html
Thing you want to do
I want to delete the element with the specified id using the delete method.
Current status
Can be saved, but cannot be deleted.
Development environment
MacOS Mojave
Intellij
Grails Version: 4.0.1
JVM Version: 11.0.2
Domain
package hoge
class Hoge {
String name
String text
static constraints = {
}
}
Controller
package hoge
class HogeController {
def index() {
render(view: '/hoge/index', model: [hoges: Hoge.listOrderById()])
}
def save() {
String text = params.text
String name = params.name
Hoge newHoge = new Hoge(name: name, text: text)
// DB save
if (newHoge.validate()) {
newHoge.save()
redirect(controller: "hoge", action: "index")
} else {
render(view: '/hoge/index', model: [errorHoge: newHoge, hoges: Hoge.listOrderById()])
}
}
def delete() {
Hoge hoge = Hoge.get(params.long("id"))
if (hoge) {
hoge.delete()
flash.message = "deleted"
} else {
flash.error = "TodoId:${params.long("id")} is not found"
}
redirect(controller: "hoge", action: "index")
}
}
View
<!DOCTYPE html>
<html>
<head>
<meta charaset="UTF-8">
<title>create page</title>
</head>
<body>
<g:if test="${flash.message}">
<div style="background-color: #269abc">${flash.message}</div>
</g:if>
<g:if test="${flash.error}">
<div style="background-color: #db7093">${flash.error}</div>
</g:if>
<g:renderErrors bean="${errorHoge}" as="list" field="hogeName"/>
<p>Name and Text</p>
<g:form controller="hoge" action="save">
<g:textField name="name" placeholder="name"/>
<g:textField name="text" placeholder="text"/>
<g:submitButton name="Add">Add Todo</g:submitButton>
</g:form>
<ul>
<g:each in="${hoges}" var="hoge">
<li>${hoge.id} ${hoge.name} ${hoge.text}</li>
<g:link controller="hoge" action="delete" params="['id':hoge.id]">
Delete
</g:link>
<g:link controller="hoge" action="update" params="['id':hoge.id]">
kousin
</g:link>
</g:each>
</ul>
</body>
build.gradle
buildscript {
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:7.0.0"
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.0.10"
}
}
version "0.1"
group "hoge"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.erdi.webdriver-binaries"
apply plugin:"org.grails.grails-gsp"
apply plugin:"com.bertramlabs.asset-pipeline"
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.4.0.Final"
compile "org.grails.plugins:gsp"
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "javax.xml.bind:jaxb-api:2.3.0"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.0.10"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.mockito:mockito-core"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.seleniumhq.selenium:selenium-remote-driver:3.14.0"
testCompile "org.seleniumhq.selenium:selenium-api:3.14.0"
testCompile "org.seleniumhq.selenium:selenium-support:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0"
}
bootRun {
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
webdriverBinaries {
chromedriver '2.45.0'
geckodriver '0.24.0'
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}
assets {
minifyJs = true
minifyCss = true
}
It remains even if I try to delete it
In case of todo.delete (flush: true)
Error 500: Internal Server Error
URI: /hoge/delete/2
Class: javax.persistence.TransactionRequiredException
Message: null
Caused by: no transaction is in progress
Related
I've been trying to publish a project to Sonatype's repository, but I got an error and I can't find the solution online.
I have the following publishing block on my build.gradle.kts file:
publishing {
publications {
create<MavenPublication>("mavenJava") {
pom {
name.set("Keen")
description.set("A genetic algorithm framework for Kotlin")
url.set("https://github.com/r8vnhill/keen")
licenses {
license {
name.set("Attribution 4.0 International (CC BY 4.0)")
url.set("https://creativecommons.org/licenses/by/4.0/legalcode")
}
}
}
groupId = "cl.ravenhill"
artifactId = "keen"
version = projectVersion
from(components["java"])
}
}
repositories {
maven {
name = "sonatype"
if (version.toString().endsWith("SNAPSHOT")) {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "ossrh"
credentials(PasswordCredentials::class)
}
} else {
maven("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
name = "ossrh"
credentials(PasswordCredentials::class)
}
}
}
}
}
And the error I've got:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToSonatypeRepository'.
> Failed to publish publication 'mavenJava' to repository 'sonatype'
> Cannot invoke "java.net.URI.getScheme()" because "repositoryUrl" is null
Any idea of what could be happening?
The repository called 'sonatype' doesn't have a URL.
Assuming the version is a snapshot version, e.g. 1.2.3-SNAPSHOT, what you've written is
repositories {
maven {
name = "sonatype"
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "ossrh"
credentials(PasswordCredentials::class)
}
}
}
This is also equivalent to
repositories {
maven {
name = "sonatype"
}
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "ossrh"
credentials(PasswordCredentials::class)
}
}
So repository 'sonatype' has a name, but doesn't have a URL.
Gradle will create a publication task for each defined repository, even if the definition isn't valid (which can't be known ahead of time). If you ran the Gradle task
./gradlew publishMavenJavaPublicationToOssrhRepository
it would succeed.
To correct the problem, remove the 'sonatype' repository. It would also be more clear if you defined the target URL in a separate variable.
val ossrhRepositoryUrl = if (version.toString().endsWith("SNAPSHOT")) {
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
publishing {
repositories {
maven(ossrhRepositoryUrl) {
name = "ossrh"
credentials(PasswordCredentials::class)
}
}
}
I have a nexus repository that I want to publish my gradles versions catalog to. Here's the gradle build script:
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.2.0")
}
}
plugins {
id ("version-catalog")
id ("maven-publish")
}
catalog {
versionCatalog {
from(files("gradle/libs.versions.toml"))
}
}
publishing {
publications {
create<MavenPublication>("VersionCatalog") {
groupId = "com.phinneyridge"
artifactId = "com.phinneyridge.version.catalog"
version = "1.0.0"
from(components["versionCatalog"])
}
repositories {
maven {
name = "PhinneyRidgeRepository"
url = uri(System.getenv()["PhinneyRidgeReleaseRepoUrl"].toString())
credentials {
username = System.getenv().get("PhinneyRidgeRepoUser").toString()
password = System.getenv().get("PhinneyRidgeRepoUserPW").toString()
}
println(url)
println(credentials.username + ":" + credentials.password)
}
}
}
}
Here's the output I get when I try to publish:
gradlew publish
Type-safe dependency accessors is an incubating feature.
Configure project :
https://ridgetop/nexus/repository/maven-releases/
publisher:mavenpublisher
Task :publishVersionCatalogPublicationToPhinneyRidgeRepositoryRepository FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':publishVersionCatalogPublicationToPhinneyRidgeRepositoryRepository'.
Failed to publish publication 'VersionCatalog' to repository 'PhinneyRidgeRepository'
java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.
SSLContextImpl$DefaultSSLContext)
If I changed the maven repository to mavenLocal(), the script actually publishes the version catalog to the local maven repository just fine.
What's also interesting, is that I have a custom gradle plugin in a different build script and it fairly well the same looking code pattern, and it successfully publishes the custom gradle plugin to same repository. Here's the code for that working script:
plugins {
id ("java-gradle-plugin")
"java-library"
id ("maven-publish")
id("com.gradle.plugin-publish") version "0.20.0"
id("org.jetbrains.kotlin.jvm") version "1.6.20"
id("org.gradle.kotlin.kotlin-dsl") version "2.1.7"
}
gradlePlugin {
group = "com.phinneyridge"
plugins {
create("PhinneyRidgePlugin") {
id = "com.phinneyridge.project"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeProjectPlugin"
}
create("PhinneyRidgeAndroidAppPlugin") {
id = "com.phinneyridge.android.application"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeAndroidAppPlugin"
}
create("PhinneyRidgeAndroidLibPlugin") {
id = "com.phinneyridge.android.library"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeAndroidLibPlugin"
}
create("PhinneyRidgeAndroidKotlinAppPlugin") {
id = "com.phinneyridge.android.kotlin.application"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeAndroidKotlinAppPlugin"
}
create("PhinneyRidgeAndroidKotlinLibPlugin") {
id = "com.phinneyridge.android.kotlin.library"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeAndroidKotlinLibPlugin"
}
create("PhinneyRidgeJavaAppPlugin") {
id = "com.phinneyridge.java.application"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeJavaAppPlugin"
}
create("PhinneyRidgeJavaLibPlugin") {
id = "com.phinneyridge.java.library"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeJavaLibPlugin"
}
create("PhinneyRidgeJavaKotlinAppPlugin") {
id = "com.phinneyridge.java.kotlin.application"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeJavaKotlinAppPlugin"
}
create("PhinneyRidgeJavaKotlinLibPlugin") {
id = "com.phinneyridge.java.kotlin.library"
implementationClass = "com.phinneyridge.android.gradle.PhinneyRidgeJavaKotlinLibPlugin"
}
create("PhinneyRidgeDSAnnotations") {
id = "com.phinneyridge.dsannotations"
implementationClass = "com.phinneyridge.osgi.DSAnnotations"
}
create("Aar2Jar") {
id = "com.phinneyridge.aar2jar"
implementationClass = "com.phinneyridge.android.Aar2Jar"
}
}
}
group = "com.phinneyridge"
version = "1.0.0"
publishing {
repositories {
maven {
url = uri(System.getenv().get("PhinneyRidgeReleaseRepoUrl").toString())
credentials {
username = System.getenv().get("PhinneyRidgeRepoUser").toString()
password = System.getenv().get("PhinneyRidgeRepoUserPW").toString()
}
}
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
gradleApi();
implementation ("com.android.tools.build:gradle:7.1.3")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20")
}
There's some differences, but the maven repository is constructed exactly the same. So the question is why am I getting the NoSuchAlgorithm error when I try to publish the version catalog?
If I try publishing with stacktrace I see the following:
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.securit
y.ssl.SSLContextImpl$DefaultSSLContext)
at org.gradle.internal.resource.transport.http.HttpClientConfigurer.jdkSupportsTLSProtocol(HttpClientConfigurer.java:115)
And here's what jdkSupportTLSProtocol looks like:
private static boolean jdkSupportsTLSProtocol(#SuppressWarnings("SameParameterValue") final String protocol) {
try {
for (String supportedProtocol : SSLContext.getDefault().getSupportedSSLParameters().getProtocols()) {
if (protocol.equals(supportedProtocol)) {
return true;
}
}
return false;
} catch (NoSuchAlgorithmException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
It's the SSLContext.getDefault() that throws the NoSuchAlgorithException. I'm just currently at a lost understand what I need to change to get around this problem.
I figured out a solution to the problem.
I added a line of code to the maven repository declaration:
maven {
javax.net.ssl.SSLContext.setDefault(javax.net.ssl.SSLContext.getInstance("default"))
name = "PhinneyRidgeRepository"
url = uri(System.getenv()["PhinneyRidgeReleaseRepoUrl"].toString())
credentials {
username = System.getenv().get("PhinneyRidgeRepoUser").toString()
password = System.getenv().get("PhinneyRidgeRepoUserPW").toString()
}
println(url)
println(credentials.username + ":" + credentials.password)
}
}
That solved the problem, but I don't have an explanation why I had to set the SSLContext in one situation and not the other. According to the gradle documentation SSLContext.getDefault() is supposeto automagically call SSLContext.getInstance("Default") when the SSLContext is not initialized. (By the way the instance name seems to be case insensitive, so "default" or "Default" both worked.) My speculation is that this is a gradle bug, probably because the publication in one case is from component. That's the only obvious difference that I see that sets the two contrasting situations apart. By the way SSLContext.getInstance("TLSv1.2") would not work; I had to use "default"
Problem Statment
I am trying to create a build and publish a library based on properties I pass in through command line. I would like to use :
./gradlew clean build publish -PnexusUsername=* -PnexusPassword=* -PmajorVersion=x -PminorVersion=x -PbuildNumber=x
Work Around
My current work around for this is I use
./gradlew clean; ./gradlew build; ./gradlew publish -PnexusUsername=* -PnexusPassword=* -PmajorVersion=x -PminorVersion=x -PbuildNumber=x
Below you will find my main build gradle. I have tried many ideas of waiting for assembleRelease to be added and publishing being finalized by it, but alas I am not a gradle expert, so I am asking for help. I have two POJO/POKO libraries and one Android Library that I am publishing out as an AAR. The error I receive is that the POM file cannot be made because the AAR does not exist.
import CiCdDependencies.BOSS_SDK_SNAPSHOT
import CiCdDependencies.buildNumber
import CiCdDependencies.majorVersion
import CiCdDependencies.minorVersion
import CiCdDependencies.nexusPassword
import CiCdDependencies.NEXUS_URL
import CiCdDependencies.nexusUserName
import CiCdDependencies.productVersion
import CiCdDependencies.VERSION_NAME
import Coverage.androidCoverage
import Coverage.testCoverage
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3")
}
}
plugins {
id("java")
id("maven-publish")
id("org.sonarqube").version("3.3")
}
ext {
// Major / Minor / Release and Build numbering
productVersion = (project.findProperty("productVersion") ?: (System.getenv("PRODUCT_VERSION")
?: "0")).toString()
majorVersion =
(project.findProperty("majorVersion") ?: (System.getenv("MAJOR_VERSION") ?: "0")).toString()
minorVersion =
(project.findProperty("minorVersion") ?: (System.getenv("MINOR_VERSION") ?: "0")).toString()
buildNumber =
(project.findProperty("buildNumber") ?: (System.getenv("BUILD_NUMBER") ?: "0")).toString()
//for publishing
nexusUserName =
(project.findProperty("nexusUsername") ?: (System.getenv("NEXUS_USERNAME"))).toString()
nexusPassword =
(project.findProperty("nexusPassword") ?: (System.getenv("NEXUS_PASSWORD"))).toString()
testCoverage = project.hasProperty("TEST_COVERAGE")
androidCoverage = project.hasProperty("ANDROID_COVERAGE")
}
description = "MAFIA BOSS SDK (Kotlin)"
allprojects {
apply {
plugin("jacoco")
}
// Read only repositories for dependencies; this should never be used to publish
repositories {
google()
mavenCentral()
maven {
name = "DI2E-BossSdkReleases"
setUrl("$NEXUS_URL$BOSS_SDK_RELEASES")
credentials {
username = nexusUserName
password = nexusPassword
}
}
maven {
name = "DI2E-BossSdkSnapshots"
setUrl("$NEXUS_URL$BOSS_SDK_SNAPSHOT")
credentials {
username = nexusUserName
password = nexusPassword
}
}
}
}
sonarqube {
properties {
val gitBranch = "git rev-parse --abbrev-ref HEAD".runCommand()
property("sonar.sourceEncoding", "UTF-8")
property("sonar.host.url", "https://sonarqube.di2e.net")
property("sonar.projectVersion", gitBranch)
property("sonar.projectKey", "MAFIA-KotlinSDK")
property("sonar.login", "c58feafd2a81797dec0361dd2d8758885e4145d7")
property("sonar.junit.reportPaths", "**/test-results/**/*.xml")
property("sonar.coverage.jacoco.xmlReportPaths", "**/reports/jacoco/jacocoTestReport/jacocoTestReport.xml")
}
}
tasks.getByName("publish").dependsOn("build")
/**
* Publishing configuration
*/
afterEvaluate {
publishing {
logger.lifecycle("Publishing ${VERSION_NAME()}")
publications {
val isSnapshot = !project.hasProperty("RELEASE")
create<MavenPublication>("BOSSSDKJAVA") {
groupId = "BOSS"
artifactId = "SDK-KOTLIN"
version = if (isSnapshot) {
"${VERSION_NAME()}-SNAPSHOT"
} else {
VERSION_NAME()
}
// The interfaces JAR
artifact("${rootProject.projectDir}/InfrastructureBase/build/libs/InfrastructureBase.jar") {
classifier = "InfrastructureBase"
}
// The implementations JAR
artifact("${rootProject.projectDir}/InfrastructureImpl/build/libs/InfrastructureImpl.jar") {
classifier = "InfrastructureImpl"
}
}
create<MavenPublication>("BOSSSDKANDROID") {
groupId = "BOSS"
artifactId = "SDK-ANDROID"
version = if (isSnapshot) {
"${VERSION_NAME()}-SNAPSHOT"
} else {
VERSION_NAME()
}
// The implementations AAR
artifact("${rootProject.projectDir}/InfrastructureAndroidImpl/build/outputs/aar/InfrastructureAndroidImpl-release.aar") {
classifier = "InfrastructureAndroidImpl"
}
}
repositories {
maven {
url = if (isSnapshot) {
logger.lifecycle("Performing snapshot build.")
uri("$NEXUS_URL$BOSS_SDK_SNAPSHOT")
} else {
logger.lifecycle("Performing release build.")
uri("$NEXUS_URL$BOSS_SDK_RELEASES")
}
credentials {
username = nexusUserName
password = nexusPassword
}
}
}
}
}
}
afterEvaluate {
tasks.getByName("jacocoTestReport", type = JacocoReport::class) {
reports {
print("I am reporting" )
xml.required.set(testCoverage)
html.required.set(testCoverage)
}
val fileFilter = mutableSetOf(
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*",
"**/*\$Lambda$*.*", // Jacoco can not handle several "$" in class name.
"**/*\$inlined$*.*" // Kotlin specific, Jacoco can not handle several "$" in class name.
)
val debugTree = fileTree("${buildDir}/tmp/kotlin-classes/debug") {
exclude(fileFilter)
}
val mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories.from(files(mainSrc))
classDirectories.setFrom(debugTree)
if (androidCoverage) {
executionData.setFrom(fileTree("$buildDir") {
include(
setOf(
"jacoco/*.exec",
"outputs/code-coverage/debugAndroidTest/connected/*coverage.ec",
"outputs/unit_test_code_coverage/*.exec"
)
)
})
} else if (testCoverage) {
executionData.setFrom(fileTree("$buildDir") {
include(
setOf(
"jacoco/*.exec",
"outputs/unit_test_code_coverage/*.exec"
)
)
})
}
configurations.all {
resolutionStrategy {
eachDependency {
if ("org.jacoco" == requested.group) {
useVersion("0.8.7")
}
}
}
}
}
}
tasks.getByName("sonarqube"){
dependsOn(tasks.getByName("jacocoTestReport"))
}
fun String.runCommand(currentWorkingDir: File = file("./")): String {
val byteOut = getByteOutput()
project.exec {
workingDir = currentWorkingDir
commandLine = this#runCommand.split("\\s".toRegex())
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}```
I believe AGP has done something to make it easier, check it here: https://developer.android.com/studio/build/maven-publish-plugin
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release
// You can then customize attributes of the publication as shown below.
groupId = 'com.example.MyLibrary'
artifactId = 'final'
version = '1.0'
}
The Android Gradle plugin creates a component for each build variant artifact in your app or library module that you can use to customize a publication to a Maven repository.
And you may need to move the android part to that android library's build.gradle(.kts).
I have a gradle script which sets the geb.build.baseUrl to be a project property. This also does not work with a static url.
This works fine on Windows, but on Linux I'm having the following issue:
org.openqa.selenium.WebDriverException at LoginTest.groovy:9
Caused by: org.openqa.selenium.firefox.NotConnectedException at LoginTest.groovy:9
org.openqa.selenium.WebDriverException
Caused by: org.openqa.selenium.firefox.NotConnectedException
When run a blank browser window is opened and the URL is not entered:
Gradle:
apply plugin: "groovy"
repositories {
mavenCentral()
}
configurations {
testCompile.transitive = true
}
dependencies {
def gebVersion = "0.10.0"
def seleniumVersion = "2.43.1"
testCompile "org.gebish:geb-spock:0.10.0"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
// Need a driver implementation
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:2.43.1"
testRuntime "org.seleniumhq.selenium:selenium-support:2.43.1"
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile "org.gebish:geb-junit4:$gebVersion"
}
test {
systemProperties "geb.build.reportsDir": "$reportsDir/geb"
systemProperties "geb.build.baseUrl": project.url
}
Spock:
package xx.xx;
import geb.spock.GebReportingSpec
class LoginSpec extends GebReportingSpec {
def "login"() {
when:
to Login
report "login screen"
and:
login(username,password)
then:
at Dashboard
where:
username | password
"X" | "X"
}
}
Geb
package xx.xx;
import geb.*
class Login extends Page {
static at = { title == "xx"}
static content = {
usernameField { $("input",id:"pt1:it1::content")}
passwordField { $("input",id:"pt1:it2::content")}
loginButton(to: Dashboard) { $("span",id: "pt1:pgl13") }
}
void login(String username, String password) {
usernameField.value username
passwordField.value password
loginButton.click()
}
}
class Dashboard extends Page {
static at = { title == "xx"}
}
When run a blank browser window is opened and the URL is not entered
From my experience, this is usually a symptom of using a Firefox version that is newer than what the used WebDriver version supports. I would suggest using selenium-firefox-driver 2.44.0 and if the symptom persist trying to downgrade Firefox.
I am using gradle as project dependency manager but since I like netbeans better and can't find a native integration with maven, I copy the default pom generated by gradle as the pom.xml. But How do I set the source and target level?
my build.gradle looks like
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'java'
targetCompatibility=1.6
sourceCompatibility=1.6
after I run
gradle install
and check the build/poms/pom-default.xml it never configures the source nor target level which is defaulted to 1.3
what I am lacking is maven compiler plugin configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
and haven't been able to find how to configure that specific part of the pom. I've found all the examples where they configure license, developer stuff and so on but not the plugin specif.
took me a while to figure it out. Like Peter said above you can just add that section. Easier said than done though, at least for me.
Fortunately, spring is using gradle so you have lots of real world examples. check git hub
install {
repositories.mavenInstaller {
customizePom(pom, project)
}
}
def customizePom(pom, gradleProject) {
pom.whenConfigured { generatedPom ->
// respect 'optional' and 'provided' dependencies
gradleProject.optionalDeps.each { dep ->
generatedPom.dependencies.find { it.artifactId == dep.name }?.optional = true
}
gradleProject.providedDeps.each { dep ->
generatedPom.dependencies.find { it.artifactId == dep.name }?.scope = 'provided'
}
// eliminate test-scoped dependencies (no need in maven central poms)
generatedPom.dependencies.removeAll { dep ->
dep.scope == 'test'
}
// add all items necessary for maven central publication
generatedPom.project {
name = gradleProject.description
description = gradleProject.description
organization {
name = 'bajoneando'
}
build {
plugins {
plugin {
groupId = 'org.apache.maven.plugins'
artifactId = 'maven-compiler-plugin'
configuration {
source = '1.6'
target = '1.6'
}
}
plugin {
groupId = 'org.apache.maven.plugins'
artifactId = 'maven-surefire-plugin'
configuration {
includes {
include = '**/*Tests.java'
}
excludes {
exclude = '**/*Abstract*.java'
}
}
}
}
resources {
resource {
directory = 'src/main/java'
includes = ['**/*']
excludes = ['**/*.java']
}
resource {
directory = 'src/main/resources'
includes = ['**/*']
}
}
testResources {
testResource {
directory = 'src/test/java'
includes = ['**/*']
excludes = ['**/*.java']
}
testResource {
directory = 'src/test/resources'
includes = ['**/*']
}
}
}
developers {
developer {
id = 'lnramirez'
name = 'Luis Ramirez Monterosa'
email = '*****#gmail.com'
}
}
}
}
}
You can add that section in the very same way as the examples do it for "license and developer stuff".