Detekt task fails only if ran without check task - gradle

I'm migrating detekt from 1.0.0.RC7-2 to the 1.0.1 and changing to use the new plugin syntax. I managed to make it work, but only when the full check task is executed.
If only the detekt task is executed then an error is shown.
The detekt task is failing with the following error:
Task :detekt FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':detekt'.
Could not resolve all files for configuration ':detekt'.
Cannot resolve external dependency io.gitlab.arturbosch.detekt:detekt-cli:1.0.1 because no repositories are defined.
Required by:
project :
detekt.gradle
apply plugin: 'io.gitlab.arturbosch.detekt'
detekt {
config = files("$rootDir/detekt/detekt-ruleset.yml")
filters = ".*build.*,.*/resources/.*,.*/tmp/.*"
input = files("src/main/java", "src/test/java")
reports {
html.enabled = true
xml.enabled = false
txt.enabled = false
}
}
build.gradle (project):
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.1"
}
build.gradle (module):
repositories {
jcenter()
google()
}
apply from: "$rootDir/detekt/detekt.gradle"

I managed to make it work by creating a task for Detekt and not using the plugin:
detekt.gradle
configurations {
detekt
}
dependencies {
detekt "io.gitlab.arturbosch.detekt:detekt-cli:1.0.1"
}
task detekt(type: JavaExec) {
main = "io.gitlab.arturbosch.detekt.cli.Main"
classpath = configurations.detekt
def input = "$rootDir"
def config = "$rootDir/detekt/detekt-ruleset.yml"
def exclude = ".*/resources/.*,.*/build/.*"
def report = "html:${project.buildDir}/reports/detekt.html"
def params = ['-i', input, '-c', config, '-ex', exclude, '-r', report]
args(params)
}
check.dependsOn detekt
build.gradle (project)
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1"
}
}

According to this issue filed on detekt repo, you have to configure it on the root project, not on the app module.

Related

ResolutionException with Hibernate and JavaFx

Im having some issue and I had no luck figuring it out how to fix it.
I have a JavaFx Project which has Hibernate and Proguard. But whenever I try to run the task 'runProguard' fails with java.lang.module.ResolutionException.
What's puzzling me is the fact that my project doesnt use modules.
Is there anyway to fix this?
Task :runProguard FAILED Task ':runProguard' is not up-to-date
because: Task has not declared any outputs despite executing actions.
Starting process 'command ... Successfully started process 'command
'C:\Program Files\Java\openjdk-11_windows-x64_bin\bin\java.exe'' Error
occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules java.activation and
activation export package javax.activation to module java.transaction
:runProguard (Thread[Daemon worker Thread 6,5,main]) completed. Took
1.094 secs.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.2.0'
}
}
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.runtime' version '1.7.1'
}
dependencies {
compile "org.controlsfx:controlsfx:11.0.0"
compile "eu.hansolo:tilesfx:11.13"
compile "com.jfoenix:jfoenix:9.0.9"
compile "org.apache.httpcomponents:httpclient:4.5.9"
compile "org.json:json:20180813"
compile "mysql:mysql-connector-java:8.0.17"
compile "org.jasypt:jasypt:1.9.3"
compile "com.sun.mail:javax.mail:1.6.2"
compile "commons-validator:commons-validator:1.6"
// https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0
compile "org.hibernate:hibernate-c3p0:5.4.7.Final"
// https://mvnrepository.com/artifact/org.hibernate/hibernate-envers
compile 'org.hibernate:hibernate-envers:5.4.8.Final'
// https://mvnrepository.com/artifact/de.jensd/fontawesomefx-commons
runtime group: 'de.jensd', name: 'fontawesomefx-commons', version: '11.0'
// https://mvnrepository.com/artifact/de.jensd/fontawesomefx-fontawesome
compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-9.1.2'
}
repositories {
jcenter()
mavenCentral()
}
javafx {
version = "13"
modules = ['javafx.controls', 'javafx.graphics', 'javafx.fxml']
}
mainClassName = 'Main'
runtime {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
jpackage {
jpackageHome = 'C:/Program Files/Java/openjdk-14-jpackage+1-49_windows-x64_bin/'
if (org.gradle.internal.os.OperatingSystem.current().windows) {
installerType = 'msi'
imageOptions = []
installerOptions = ['--win-per-user-install',
'--win-dir-chooser',
'--win-menu',
'--win-shortcut',
'--verbose',
'--description', 'Test of proguard with jPackage',
'--name', 'Test-ProguardJPackage',
'--vendor', 'DoesItMatter']
}
}
}
jar {
dependsOn 'cleanAfterProguard'
manifest {
attributes(
'Main-Class': 'org.openjfx.Launcher'
)
}
from zipTree("${buildDir}/proguard/output.jar")
}
task cleanClasses(type: Delete) {
delete "${buildDir}/classes/java/main"
delete "${buildDir}/resources/java/main"
}
classes.dependsOn(cleanClasses)
// 2.2 Add proguard task
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: classes) {
injars project.sourceSets.main.output
outjars "${buildDir}/proguard/output.jar"
libraryjars project.sourceSets.main.compileClasspath
configuration 'proguard.conf'
}
// 2.3 Clean after proguard task
task cleanAfterProguard(type: Delete, dependsOn: proguard) {
delete "${buildDir}/classes/java/main"
delete "${buildDir}/resources/java/main"
}
// 2.4 Extract output jar to buildDir
task unpackProguardOutput(type: Copy, dependsOn: cleanAfterProguard) {
from zipTree("${buildDir}/proguard/output.jar")
into file("${buildDir}/classes/java/main")
}
// 3. Create a task to run the app with the proguarded buildDir
task runProguard(type: JavaExec, dependsOn: unpackProguardOutput) {
classpath = sourceSets.main.runtimeClasspath
jvmArgs = ['--module-path', classpath.asPath,
'--add-modules', 'javafx.controls,javafx.fxml']
main = 'Main' // <-- this name will depend on the proguard result
}
jar.dependsOn(unpackProguardOutput)
This is the repo:
https://github.com/KenobySky/hellofx

AndroidX. Could not determine artifacts for androidx.multidex:multidex:2.0.0

I try to migrate a project to AndroidX.
After 3 minutes of migrating it finished with error:
Gradle import
errorsC:\Users\user\AndroidStudioProjects\project\app\build.gradleproject
':app': Unable to build Kotlin project configurationDetails:
org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration
':app:implementationDependenciesMetadata'.Caused by:
org.gradle.internal.resolve.ArtifactResolveException: Could not
determine artifacts for androidx.room:room-runtime:2.0.0Caused
by: org.gradle.api.resources.ResourceException: Could not get resource
'https://dl.google.com/dl/android/maven2/androidx/room/room-runtime/2.0.0/room-runtime-2.0.0.aar'.Caused
by: org.gradle.internal.resource.transport.http.HttpRequestException:
Could not HEAD
'https://dl.google.com/dl/android/maven2/androidx/room/room-runtime/2.0.0/room-runtime-2.0.0.aar'.Caused
by: javax.net.ssl.SSLHandshakeException: Remote host closed connection
during handshakeCaused by: java.io.EOFException: SSL peer shut
down incorrectly
FAILURE: Build failed with an exception.
What went wrong:
Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
Could not determine
artifacts for androidx.multidex:multidex:2.0.0
Could not get resource 'https://dl.google.com/dl/android/maven2/androidx/multidex/multidex/2.0.0/multidex-2.0.0.aar'.
Could not HEAD 'https://dl.google.com/dl/android/maven2/androidx/multidex/multidex/2.0.0/multidex-2.0.0.aar'.
Remote host closed connection during handshake SSL peer shut down incorrectly
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.
Get more help at https://help.gradle.org
How to solve a problem with multidex and Maven?
build.gradle (project):
buildscript {
ext.compile_sdk_version = 29
ext.min_sdk_version = 16
ext.target_sdk_version = 29
ext.kotlin_version = '1.3.40'
ext.supportLibraryVersion = "28.0.0"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Firebase.
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
signingConfigs {
...
}
compileSdkVersion compile_sdk_version
defaultConfig {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexEnabled true
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// Adds the "release" signing configuration to the release build type.
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.0'
}
UPDATE
I updated all libraries in dependencies. Then in project's build.gradle I added
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
to repositories in both branches. After compilation I got:
What went wrong: Could not determine the dependencies of task ':app:kaptDebugKotlin'.
Could not resolve all task dependencies for configuration ':app:kapt'.
Could not resolve androidx.room:room-compiler:2.1.0.
Required by:
project :app
Could not resolve androidx.room:room-compiler:2.1.0.
Could not get resource 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Could not GET 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Remote host closed connection during handshake
Could not resolve androidx.room:room-compiler:2.1.0.
Could not get resource 'https://maven.google.com/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Could not GET 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Remote host closed connection during handshake
I added in build.gradle (project) these lines:
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
So, it looks like:
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.40"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Then synced gradle file. It downloaded some libraries from Maven. After compiling I got another error. Then I pressed Sync Project with Gradle files again.
See also https://developer.android.com/jetpack/androidx/migrate to understand what library and styles becomes what in AndroidX.
Strange, but after compiling and removing
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
back from build.gradle, the application run again.

Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2) flutter project

I have an error with lint-gradle-api.jar, I looked at other similar questions on the forums but I still have the problem.
Does anyone have an idea ?
Error running Gradle:
Exit code 1 from: C:\Users\bgbra\Documents\Flutter_apps\flutter_app\android\gradlew.bat app:properties:
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\bgbra\Documents\Flutter_apps\flutter_app\android\app\build.gradle' line: 25
What went wrong:
A problem occurred evaluating project ':app'.
Could not resolve all artifacts for configuration 'classpath'.
Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
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.
build.gradle
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my build.gradle file. I don't know, will it help you.
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
// global properties used in sub modules
ext {
versionCodeProp = 81100
versionNameProp = "0.8.11-dev"
versionBuild = System.getenv("BUILD_NUMBER") as Integer ?: 0
buildNumberProp = "${versionBuild}"
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
Probably you shoul add maven to allprojects branch.

How to compile Kotlin domain module with client module with Gradle?

I have the following project structure:
- parent
- - client (written in Kotlin but compiled to JS)
- - server (written in Kotlin)
- - model (written in Kotlin)
client module has a dependency on model. So when I compile client to JS it also should compile model with it. For now I have the following Gradle configurations which are not doing the desired thing:
project/parent.gradle
group 'com.vchernogorov.tycher'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile project(":model")
compile project(":client")
compile project(":server")
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
project/settings.gradle
rootProject.name = 'parent'
include ':model'
include ':server'
include ':client'
project/model/build.gradle
group 'com.vchernogorov.tycher'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
project/client/build.gradle
group 'com.vchernogorov.tycher'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile project(":model")
}
build.doLast {
configurations.compile.each { File file ->
copy {
includeEmptyDirs = false
from zipTree(file.absolutePath)
into "${projectDir}/web"
include { fileTreeElement ->
def path = fileTreeElement.path
path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
}
}
}
}
When I run gradle build command on client I get this message:
:model:compileKotlin
Using kotlin incremental compilation
:model:compileJava UP-TO-DATE
:model:copyMainKotlinClasses
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:jar
:client:compileJava UP-TO-DATE
:client:compileKotlin2Js
e: project/client/src/main/kotlin/HelloWorld.kt: (30, 19): Unresolved reference: Position
e: project/client/src/main/kotlin/HelloWorld.kt: (50, 5): Unresolved reference: Test
e: project/client/src/main/kotlin/SocketHandler.kt: (10, 36): Unresolved reference: User
:client:compileKotlin2Js FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':client:compileKotlin2Js'.
> Compilation error. See log for more details
* 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: 13.891 secs
These 3 classes are defined in model.
So what should I do to successfully compile client and not changing the code?
I have developed the following architecture for my application:
I have client,server and model modules but also I have a separate source directory with DTOs called dto (not module btw). Here's the dependency hierarchy for the build:
client depends on dto
server depends on model
model depends on dto
With such hierarchy model can still use stdlib functionality and server will share all DTOs with client module. Meanwhile dto module will use the stdlib if it's compiled as module dependency and stdlib-js if it's compiled as client dependency, so it important to remember which classes you are able to use there.
In order to achieve this, you need to add
sourceSets.main.kotlin.srcDirs += '../dto/src/main/kotlin
config to both client and model build.gradle files. For Gradle Kotlin DSL:
the<JavaPluginConvention>().sourceSets {
"main" {
java {
srcDirs("../dto/src/main/kotlin")
}
}
}

Allure report is empty when use Allure2+Junit5+Gradle+Selenide

My build.gradle is:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'io.qameta.allure'
defaultTasks 'clean', 'test'
ext.junitJupiterVersion = '5.0.0-M4'
ext.selenideVersion = '4.4.3'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.encoding = 'UTF-8'
options.compilerArgs += "-parameters"
}
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
jcenter()
mavenCentral()
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4'
classpath 'io.qameta.allure:allure-gradle:2.3'
}
}
allure {
aspectjweaver = true
autoconfigure = true
version = '2.1.1'
}
configurations {
agent
}
dependencies {
// JUnit5
compile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
compile("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
// Selenide
compile("com.codeborne:selenide:${selenideVersion}") {
exclude group: 'junit'
}
// Allure
agent 'org.aspectj:aspectjweaver:1.8.10'
compile 'ru.yandex.qatools.allure:allure-junit-adaptor:1.4.23'
compile 'io.qameta.allure:allure-junit5:2.0-BETA6'
}
junitPlatform {
platformVersion = "1.0.0-M5"
enableStandardTestTask = true
}
task runJupiter(type: JavaExec) {
jvmArgs '-ea'
jvmArgs "-javaagent:${configurations.agent.singleFile}"
classpath = project.sourceSets.test.runtimeClasspath
main 'org.junit.platform.console.ConsoleLauncher'
args '--scan-class-path'
args "--reports-dir=${buildDir}/allure-results"
finalizedBy 'allureReport'
}
test.dependsOn runJupiter
Tests are finished successfully and three folders are created automatically:
{projectDir}\allure-results with .json file
{projectDir}\build\test-results\junit-platform with TEST-junit-jupiter.xml file
{projectDir}\build\reports\allure-report
I tried to open .json and .xml result locally via allure command line (CLI). The allure report is opened but it is blank:
this is a report view
I suppose my mistake in gradle dependencies. I quite confused which libraries and versions should be used for JUnit5+Allure2+Gradle+Selenide+Java8?
The JUnit Platform Gradle plugin does currently not use the test task (it needs changes in Gradle core in order to do so). Thus, things like test.doFirst {...} are not going to work.
Instead of using the plugin, you should be able to create your own task that runs the ConsoleLauncher and add the JVM agent there. See https://stackoverflow.com/a/43512503/6327046 for an example.

Resources