The Stackoverflow contains some questions regarding this issue but unfortunately, nothing works for me. For example, I read this
My build.gradle looks like this:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
id 'net.linguica.maven-settings' version '0.5'
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
sourceCompatibility = '11'
targetCompatibility = '11'
mavenSettings {
userSettingsFileName project.getProperty('settingsXml')
}
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
// This configuration is necessary for publishing spring boot jar
configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
}
group 'com.something.company'
version '1.0.0-SNAPSHOT'
repositories {
maven {
name 'nexus.aliter.com'
url 'https://nexus.aliter.com/repository/cloud-maven/'
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
name 'nexus.aliter.com'
if(project.version.endsWith('-SNAPSHOT')) {
url 'https://nexus.repo.com/repository/maven-snapshots/'
} else {
url 'https://nexus.repo.com/repository/maven-releases/'
}
}
}
}
springBoot {
buildInfo()
}
test {
useJUnitPlatform()
}
dependencies {
implementation group: 'com.aliter.csp', name: 'security-lib', version: '1.0.0-SNAPSHOT'
implementation group: 'com.aliter.csp', name: 'adapter-lib', version: '1.0.0-SNAPSHOT'
}
I tried this:
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
and I tried keyword changing: true, I tried gradle clean build --refresh-dependencies and nothing works for me. The gradle shows me that cannot find the snapshot dependencies.
We build the project through Jenkins, so in the matter of automation, it is necessary to not delete .gradle/cache every time. I am 100% percent sure that snapshot dependencies are available in the nexus repository.
Gradle version: 6.6.1
I found the solution, problem was that the nexus repository missed this maven-metadata.xml
Related
I had a problem when dockerize the Gradle project.
running gradle jib
What went wrong:
Execution failed for task ':jib'.
Invalid image reference registry.hub.docker.com/myusername/${rootProject.name}, perhaps you should check that the reference is formatted correctly according to https://docs.docker.com/engine/reference/commandline/tag/#extended-description
For example, slash-separated name components cannot have uppercase letters
Root Module
setting.gradle
rootProject.name = 'myproject'
include 'discovery-service'
include 'client-service'
include 'notification-service'
include 'api-gateway'
build.gradle
jib {
var tag = 'latest'
from {
image = 'eclipse-temurin:17.0.4.1_1-jre'
}
to {
image = 'registry.hub.docker.com/myUsername/${rootProject.name}'
}
}
One of the service
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.leekify'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
jar {
baseName = 'client-service'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
....
}
tasks.named('test') {
useJUnitPlatform()
}
setting.gradle
rootProject.name = 'client-service'
Use double-quotes instead of single quotes for the jib.to.image string so that Gradle evaluates the variable.
I'm having a JavaFX project configured with Gradle in IntelliJ.
Whenever I'm trying to run gradlew.bat clean build or simply the build task directly from IntelliJ, this is what I receive:
> Task :startScripts FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':startScripts'.
> Couldn't replace placeholder in E:\git\yuber\build\scripts\yuber
I'm also using the shadowJar plugin, which actually works when I'm trying to create a jar file and run it. And it works perfectly. Although, I'm not sure why it won't build. Looked everywhere for an answer, but seems that no one actually had this problem at this moment?
This is my build.gradle file:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
sourceCompatibility = '11'
targetCompatibility = '11'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example.yuber'
mainClass = 'com.example.yuber.Launcher'
}
javafx {
version = '11.0.2'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.0')
implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.1.13') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('eu.hansolo:tilesfx:11.48') {
exclude(group: 'org.openjfx')
}
implementation 'org.json:json:20220320'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2'
implementation 'junit:junit:4.13.1'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
Updating the org.openjfx.javafxplugin (https://plugins.gradle.org/plugin/org.openjfx.javafxplugin) to the latest version inside build.gradle (from 0.0.10, as IntelliJ added it, to 0.0.13) seemed to have fixed the problem.
Jitpack builds my project with this logs. As you can see there is an error: "ERROR: No build artifacts found".
What i do wrong?
Here is my gradle.build:
plugins {
id 'java'
id 'maven-publish'
}
group 'com.github.azzztec'
version '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
wrapper {
gradleVersion = "7.0.2"
distributionType = Wrapper.DistributionType.ALL
}
I got the same issue as you, then I fixed it by following these steps:
Add publish plugin
id 'maven-publish'
Custom publishing
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'org.gradle.sample'
artifactId = 'library'
version = '1.1'
from components.java
}
}
}
You can see the full example here:
https://github.com/hukacode/huka-common/blob/main/build.gradle
I have java and kotlin based multi module gradle project. I am trying to setup sonar analysis for the same. I configured sonar at root project and ran analysis with CircleCI. The result in sonarcloud gets for only one of the sub-project.
My project structure is as below:
projectA/build.gradle
ProjectB/build.gradle
ProjectC/build.gradle
build.gradle
Here is my root build.gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61'
classpath 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
}
}
ext {
springCloudVersion = 'Hoxton.SR1'
springBootVersion = '2.2.4.RELEASE'
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
allprojects {
group = 'com.organiz'
version = '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
// url ="s3url" // only for releases
url ="s3url" // only for snapshots
credentials(AwsCredentials) {
accessKey project.accessKey
secretKey project.secretKey
}
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
apply plugin: 'org.sonarqube'
sourceCompatibility = '1.8'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation('someappcommon:1.0.0-SNAPSHOT') { changing = true }
implementation("com.h2database:h2:1.4.200")
}
repositories {
mavenCentral()
jcenter()
maven {
url "someurlhere"
}
someappMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
}
test {
useJUnitPlatform()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
sonarqube {
properties {
property "sonar.projectKey", "projectKey"
property "sonar.organization", "org"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.verbose", "true"
}
}
}
project(':project1') {
dependencies {
implementation project(":common")
}
}
project(':project2') {
dependencies {
implementation project(":common")
}
}
Need to include sonarqube outside the subproject block and then all the sub modules will be analysed and report will be exported.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61'
classpath 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
}
}
ext {
springCloudVersion = 'Hoxton.SR1'
springBootVersion = '2.2.4.RELEASE'
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
allprojects {
group = 'com.organiz'
version = '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
// url ="s3url" // only for releases
url = "s3url" // only for snapshots
credentials(AwsCredentials) {
accessKey project.accessKey
secretKey project.secretKey
}
}
}
}
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.projectKey", "projectKey"
property "sonar.organization", "org"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.verbose", "true"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
sourceCompatibility = '1.8'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation('someappcommon:1.0.0-SNAPSHOT') { changing = true }
implementation("com.h2database:h2:1.4.200")
}
repositories {
mavenCentral()
jcenter()
maven {
url "someurlhere"
}
someappMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
}
test {
useJUnitPlatform()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
project(':project1') {
dependencies {
implementation project(":common")
}
}
project(':project2') {
dependencies {
implementation project(":common")
}
}
My solution for kotlin multi-module project with junit 5 & spring boot, using gradle-jacoco-log plugin:
1.☝🏻 In your root build.gradle.kts:
plugins {
kotlin("jvm") version "1.5.0"
id("org.sonarqube") version "3.2.0"
id ("org.barfuin.gradle.jacocolog") version "1.2.4"
}
sonarqube {
val sonarOrganization: String by project
val sonarProjectKey: String by project
val sonarLogin: String by project
properties {
properties(
hashMapOf<String, String>(
"sonar.login" to sonarLogin,
"sonar.projectKey" to sonarProjectKey,
"sonar.organization" to sonarOrganization,
"sonar.host.url" to "https://sonarcloud.io",
"sonar.coverage.jacoco.xmlReportPaths" to "${buildDir}/reports/jacoco/jacocoAggregatedReport/jacocoAggregatedReport.xml"
)
)
}
}
2.👉🏻 In backend suprojects which have tests:
plugins{
jacoco
}
jacoco { toolVersion = "0.8.7" }
tasks{
test { useJUnitPlatform()
jacocoTestReport { reports { xml.required.set( true ) } }
finalizedBy(jacocoTestReport)
}
}
Optional step (example how to use)
3.👌🏻 In your CI file (.github/workflows/master.yml in my case):
name: Master CI
on:
push:
branches:
- master
jobs:
DEPLOY:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: 🪜 Set up JDK 16
uses: actions/setup-java#v1
with:
java-version: 16
- name: 🔦 Test
run: |
chmod +x ./gradlew
./gradlew test
# Create `build/jacoco/jacocoMergeSubprojects.exec`
- name: ⛈ 1) Jacoco merge subprojects reports
run: ./gradlew jacocoMergeSubprojects -x test
# Create `build/reports/jacoco/jacocoAggregatedReport/jacocoAggregatedReport.xml`
- name: ⛈ 2) Jacoco Jacoco aggregated report
run: ./gradlew jacocoAggregatedReport -x test
- name: ⛈ 3) Sonarqube report
run: ./gradlew sonarqube -x test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
I'm having difficulty generating a Grails 3.2.7 plugin with its dependencies.
This works and creates a JAR with all dependencies:
gradle clean build
..but not this; the JAR has no dependencies, just plugin project files:
gradle publishToMavenLocal
My gradle file, I know there's something missing, and based on the docs it's my understand there's no native feature to do this.
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id "com.jfrog.bintray" version "1.2"
}
version "3.1-SNAPSHOT"
group "mygroup"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.springframework.boot"
apply plugin: "com.jfrog.artifactory"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"
apply plugin: 'maven-publish'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
idea {
module {
downloadSources = true
}
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
compile "org.grails:grails-plugin-testing"
testCompile "com.fiftyonred:mock-jedis:0.4.0"
console "org.grails:grails-console"
compile "redis.clients:jedis:2.5.2"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
artifactory {
contextUrl = 'http://myrepo/'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
The issue stems from the publishing section:
When I change this to:
task jarWithPlainPom(type: Jar) {
from sourceSets.main.output
from configurations.runtime
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact jarWithPlainPom
}
}
}
It includes most of the needed dependencies, however the POM is not updated and the project fails when importing the plugin.