Trouble consuming Gradle plugin project with 3rd party maven repository - gradle

I am attempting to create a Gradle plugin that is set up like this:
plugins {
id 'java-gradle-plugin'
id 'groovy'
}
repositories {
mavenCentral()
jcenter()
// note the custom maven repo
maven { url = "https://maven.gentics.com/maven2" }
}
dependencies {
implementation gradleApi(),
localGroovy(),
"com.gentics.mesh:mesh-rest-client:${MESH_VER}"
testImplementation gradleTestKit()
testImplementation("org.spockframework:spock-core:${SPOCK_VER}") {
exclude module : 'groovy-all'
}
}
// the rest...
However if I try to consume this plugin in another project with includeBuild "./gradle-mesh" in the settings.gradle, I get the following error:
A problem occurred configuring root project 'functionalTest'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.gentics.mesh:mesh-rest-client:1.7.1.
Searched in the following locations:
- https://plugins.gradle.org/m2/com/gentics/mesh/mesh-rest-client/1.7.1/mesh-rest-client-1.7.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project : > project :gradle-mesh
However, I am able to execute the functionalTest in the actual plugin tests without issue. Getting rid of that line in the settings.gradle and renaming the folder to buildSrc works as well.
Is there a way to configure the buildscript dependencies from within the plugin entry point? I tried the following, but it didn't make any difference.
class GradleMeshPlugin implements Plugin<Project> {
public void apply(Project project) {
project.buildscript.repositories.configure {
mavenLocal()
jcenter()
maven { url = "https://maven.gentics.com/maven2" }
}
// dependency is referenced here...
}
}
Any ideas how to go about this?
Full Project: https://github.com/wawebio/gradle-mesh
System:
------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------
Build time: 2020-08-25 16:29:12 UTC
Revision: f2d1fb54a951d8b11d25748e4711bec8d128d7e3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OS: Linux 5.4.0-47-generic amd64
Update
I was also able to get it to work by adding the following in the consuming project's settings.gradle
pluginManagement {
repositories {
mavenCentral()
jcenter()
maven { url = "https://maven.gentics.com/maven2" }
}
}
rootProject.name = 'website'
includeBuild "./gradle-mesh"
Is there a way to do this from within the plugin application itself?

You need to specify your mvn package‌‌‌​​‌​‌‌​‌‌‌‌‌‌​​​‌​‌‌​‌‌‌‌ differently, which is the first one.
<configuring-project>

Related

Could not get unknown property 'enforcer' for extension 'enforce'

I tried to use the gradle plugin 'org.kordamp.gradle.enforcer' but get the error message "Could not get unknown property 'enforcer' for extension 'enforce'" when I start gradle (e.g. ./gradlew clean). I've tried several gradle version (6.9, 7.4, 7.5) and an older version of the plugin (0.9.0).
My project has a simple settings.gradle:
rootProject.name = 'EnforceTest'
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'org.kordamp.gradle:enforcer-gradle-plugin:0.10.0'
}
}
apply plugin: 'org.kordamp.gradle.enforcer'
enforce {
rule(ruleType: enforcer.rules.BanDulicateClasses)
}
What is the reason for the error? Any idea is appreciated :-)

Gradle doesn't find plugins: org.jetbrains.kotlin.jvm and kotlin2js

I'm a beginner in gradle, using version 4.8.
Whatever I do , the plugins are never found. I get this error message:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.3.20'] 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.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.3.20')
Searched in the following repositories:
Gradle Central Plugin Repository
No matter how many repositories I add, it seems it is only looking in "Gradle Central Plugin Repository"
My gradle.build file:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
classpath "org.jetbrains.kotlin.jvm:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
id 'kotlin2js' version '1.3.20'
}
Can you help me?
Try the following gradle.build configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
When you include the plugin by id, it seems Gradle wants to retrieve the plugin from the Gradle plugin portal, but the Kotlin plugin is not there, it's part of the buildscript dependency. Using it with the apply plugin works. You can also find a slightly different working example here.
I had similar problem because i forgot about proxy settings like systemProp.https.proxyHost and systemProp.http.proxyHost and etc. that was set in ~/.gradle/gradle.properties.
I fixed configuration and plugin was successfully dowlnloaded
Check gradle.properties and try to add correct proxy settings if you behind firewall or escape this settings if you not.
you need to add repository mavenCentral() to the buildscript dependencies.
for example: kotlin-gradle-plugin:1.3.20. also the documentation hints for that.
Go to your project and then to the Gradle script. In Gradle, Go to Setting.Gradle and change the Fist Bitray Url to https://plugins.gradle.org/m2/.

Kotlin Require Library with Gradle Build

I'm trying to add the library Exposed to my project. So, it leads me to the bintray page where it says to use compile 'org.jetbrains.exposed:exposed:0.8.5'. I open my file build.gradle and place that file into the dependencies segment:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'org.jetbrains.exposed:exposed:0.8.5'
}
IntelliJ auto builds it and I get the following error
Warning:root project 'DB-Table-To-Orm': Unable to build Kotlin
project configuration Details:
java.lang.reflect.InvocationTargetException: null Caused by:
org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration ':compileClasspath'. Caused by:
org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not
find org.jetbrains.exposed:exposed:0.8.5. Searched in the following
locations:
https://repo1.maven.org/maven2/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.pom
https://repo1.maven.org/maven2/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.jar
Required by:
project :
So, I look in the repo and there is no path beyond jetbrains with the exposed directory.
How do I install the Exposed library with Gradle? Do they have the path written down incorrectly? Should I put in a bug report with the project? Or am I just putting the compile statement in the wrong location?
Sorry, if this seems like a silly request, I'm new to Javaland and Kotlin and IntelliJ. Coming for the .NET world.
Update
Here's the build.gradle in its entirety:
group 'com.awebsite.db-table-to-orm'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.4-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'org.jetbrains.exposed:exposed:0.8.5'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
As far as I know Exposed isn't in the main bintray repo (aka jcenter). To make gradle search in Exposed's repo you need to add this:
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
to your repositories section.
Example:
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
}
Then just rebuild and it should work just fine

Gradle maven-publish for Spring-Boot project throws error: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for project

I am new to Gradle so any help with this error will be highly appreciated.
I am building a REST based service using Spring-boot. I want to publish the JAR file to the local maven repository so that my web application can use it. After trying many things, I finally settled for maven-publish plugin. Here is my build.gradle file
//Needed for spring-boot
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE")
}
}
apply plugin: 'eclipse'
// Apply the groovy plugin to add support for Groovy
apply plugin: 'groovy'
//apply Spring-boot plugin
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
// In this section you declare where to find the dependencies of your project
repositories {
mavenLocal()
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
group = "com.proto"
publishing {
publications {
maven(MavenPublication) {
groupId "${project.group}"
artifactId "${project.name}"
version "${project.jar.version}"
artifact sourceJar { classifier "sources" }
from components.java
pom.withXml {
asNode().appendNode('parent')
.appendNode('groupId', 'org.springframework.boot').parent()
.appendNode('artifactId', 'spring-boot-starter-parent').parent()
.appendNode('version', '1.1.8.RELEASE')
asNode().appendNode('repositories').appendNode('repository')
.appendNode('id', 'spring-releases').parent()
.appendNode('url', 'http://repo.spring.io/libs-release')
}
}
}
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
jar {
baseName = 'my-api'
version = '0.0.1'
}
task('execJar', type:Jar, dependsOn: 'jar') {
baseName = 'my-api'
version = '0.0.1'
classifier = 'exec'
from sourceSets.main.output
}
bootRepackage {
withJarTask = tasks['execJar']
}
// In this section you declare the dependencies for your production and test code
dependencies {
// We use the latest groovy 2.x version for building this library
compile 'org.codehaus.groovy:groovy-all:2.3.6'
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web")
// {
// exclude module: "spring-boot-starter-tomcat"
// }
// compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// We use the awesome Spock testing and specification framework
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'junit:junit:4.11'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('cglib:cglib:3.1')
}
// tag::wrapper[]
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
My problem is that, when I run:
gradle publishToMavenLocal
I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'MavenLocal'
> Unable to initialize POM pom-default.xml: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for project: com.proto:proto-api:jar:0.0.1 for project com.proto:proto-api:jar:0.0.1
My gradle environment details:
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time: 2014-09-08 10:40:39 UTC
Build number: none
Revision: e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_72 (Oracle Corporation 24.72-b04)
OS: Linux 3.13.0-39-generic amd64
What am I missing?
Thank you in advance for your help.
Ok, I have fixed the issue.
I am behind our corporate firewall, and had configured proxy correctly for gradle in ~/.gradle/gradle.properties file. But, I missed setting proxies for maven in ~/.m2/settings.xml file.
I configured our internal nexus repository to handle this issue but setting proxies block should work as well. Click here for maven settings.xml documentation
Same as #aardee, I am sitting behind our corporate firewall but it seems that my proxy settings (settings.xml) for maven local did not change anything. Fortunately we have our own maven repository that can proxy out and so I just replaced the repository in the generated pom and made sure that our company maven repository knows the relevant spring repos.
pom.withXml {
asNode().appendNode('parent')
.appendNode('groupId', 'org.springframework.boot').parent()
.appendNode('artifactId', 'spring-boot-starter-parent').parent()
.appendNode('version', '1.1.8.RELEASE')
asNode().appendNode('repositories').appendNode('repository')
.appendNode('id', 'spring-releases').parent()
.appendNode('url', 'http://my.mavenRepo.com/releases}
Replace http://my.mavenRepo.com/releases with your own maven repository.

Android Studio / gradle: "Could not create plugin of type 'LibraryPlugin'"

I have two modules in Android Studio.
Main is the application and Sub is a library module. Sub is referred from Main with compile project(':Sub') in the gradle script. That works when run from Android Studio. But when run from command line, gradlew says:
Could not create plugin of type 'LibraryPlugin'.
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/artifacts/result/ResolvedComponentResult
This is the important parts in Main's build.gradle file:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
gradleVersion = '1.11'
}
android {
buildToolsVersion '19.0.3'
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project (':Sub')
}
The Sub gradle file is more or less identical, but has
apply plugin: 'android-library'
instead of 'android'
I have tried with gradle 1.9 and 1.10, but same result.
Anyone knows how to solve this?
Verify that your dependencies contains classpath 'com.android.tools.build:gradle:0.9.+' in each gradle.build file (or just put it in the base one and not declare it in the others). Update gradle/wrapper/gradle-wrapper.properties to point to gradle 1.11:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
If you have any other instances of the gradle-wrapper (such as if you originally made the library project on its own and later added an example app), verify that all instances are updated to point to the same version (each gradle-wrapper.properties file).

Resources