GradleCMPlugin in shared file does not work - any workarounds? - plugins

I am trying to apply common code that uses GradleCMPlugin:
file common/gradlecm.gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'http://kercheval.org/mvn-repo/releases' }
}
dependencies { classpath("org.kercheval:GradleCMPlugin:+") }
}
apply plugin: org.kercheval.gradle.buildvcs.BuildVCSPlugin
apply plugin: org.kercheval.gradle.buildinfo.BuildInfoPlugin
apply plugin: org.kercheval.gradle.buildrelease.BuildReleasePlugin
apply plugin: org.kercheval.gradle.buildversion.BuildVersionPlugin
apply plugin: org.kercheval.gradle.gradlecm.GradleCMPlugin
In my build.gradle file:
apply from: rootProject.file('common/gradlecm.gradle')
I am getting error:
Failed to apply plugin [class 'org.kercheval.gradle.buildinfo.BuildInfoPlugin']
Plugin with id 'buildvcs' not found.
It looks like GradleCM plugins reference each other by ID:
https://github.com/kercheval/GradleCMPlugin/blob/master/src/main/java/org/kercheval/gradle/gradlecm/GradleCMPlugin.java
I fould Gradle bug report from 2012:
http://issues.gradle.org/browse/GRADLE-2136
Is there any workaround?

The latest release of GradleCM plugin:
https://github.com/kercheval/GradleCMPlugin/tree/release
includes workaround.

Related

How can I apply Gradle plugin from directly GitHub repo

I tried to apply plugin directly from GitHub repo e.g. as given below
apply from 'https://github.com/gradle/gradle-hello-world-plugin' but on running
./gradlew codeLines
It gives me error as
* Where:
Script 'https://github.com/SurpSG/code-lines-counter-gradle-plugin' line: 7
* What went wrong:
Could not compile script 'https://github.com/SurpSG/code-lines-counter-gradle-plugin'.
> startup failed:
script 'https://github.com/SurpSG/code-lines-counter-gradle-plugin': 7: unexpected token: < # line 7, column 1.
<!DOCTYPE html>
^
How can I directly apply plugin from remote git repo?
The plugin is automatically published to jitpack.
You could apply the plugin in the next way:
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.github.SurpSG:code-lines-counter-gradle-plugin:0.0.1'
}
}
apply plugin: 'com.github.code-lines'
Note! code-lines-counter-gradle-plugin is sample project created as a part of tutorial.
I don't recommend to use it because it far from production ready
I don't think it's possible. The closest think you can do is clone the plugin, build it and point to it
buildscript {
repositories {
[...]
}
dependencies {
classpath files('relative/path/to/gradle-hello-world-plugin.jar')
}
}
apply plugin: org.gradle.plugin.HelloWorldPlugin
Source : https://stackoverflow.com/a/35472676/2003986

HMS Ads Kit - Could not resolve com.huawei.hms:ads-lite:13.4.29.303

Actually i was trying to implement ads but i did everything with instruction of codelab but this message is showing .... how can resolve this problem.??
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.huawei.hms:ads-lite:13.4.29.303.
Thanks
Have you added this plugin in top of your app build.gradle?
apply plugin: 'com.huawei.agconnect
Also make sure you have added below code in top-level build.gradle
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
Please verify your top level build.gradle looks like this:
enter image description here
After that, verify you are not using proxy settings:
Go to Settings -> Appearance & Behavior -> System Settings ->HTTP Proxy
Finally go to File-> Invalidate Caches / Restart
enter image description here

Intellij gradle sync error: scala import error

I have updated my IntelliJ and the gradle sync outputs a warning which affects my IDE autocomplete.
I have tried looking for this problem and I've tried some fixes with package versions or change from compile to implementation, but none have worked.
Here is my gradle part that seems to generate the error.
allprojects {
apply plugin: 'java'
apply plugin: 'scala'
group = 'com.adobe.platform.activation'
sourceCompatibility = 1.8
// Once we migrate to our own jenkins, this will be removed
String gitBranch = System.getenv("GIT_BRANCH")
if (gitBranch != null && gitBranch != "master") {
String version = version.toString()
int dashIndex = version.lastIndexOf('-')
String prefix = version.substring(0, dashIndex)
String suffix = version.substring(dashIndex + 1)
String newVersion = "$prefix-$gitBranch-$suffix"
.replace("/", "-")
.replace("_", "-")
setVersion(newVersion)
}
}
The warning looks like this.
Warning:<i><b>root project '....': Unable to build Scala project configuration</b>
Details: org.gradle.api.GradleException: Cannot infer Scala class path because no Scala library Jar was found. Does root project '...' declare dependency to scala-library? Searched classpath: file collection.</i>
Apparently, replacing allprojects with subprojects seems to fix the problem.
Somehow, the project wanted to set the scala library for the root of the project, which contains no code.

Gradle + Scala + Intellij "Create separate module per source set"

Gradle version: 4.2.2.
Intellij version: 2019.1.1.
I am trying to setup a Scala/Gradle project in Intellij (via importing the build.gradle) using the "Create separate module per source set" option enabled.
Whenever I enable this option, Intellij doesn't identify that its a Scala project so I can't create Scala files. Without this option checked - it works perfectly.
My file structure:
/service1/api/scala
/service1/main/scala
/service2/api/scala
/service2/main/scala
/build.gradle
/settings.gradle
My build.gradle file looks like this:
apply plugin: "idea"
subprojects {
apply plugin: "scala"
configurations {
api
apiCompile.extendsFrom(compile)
}
sourceSets {
api {
scala.srcDirs = ["api/scala"]
}
main {
scala.srcDirs = ["main/scala"]
}
}
dependencies {
zinc ... // some zinc dependencies - not important
compile files("D:\\scala-library-2.12.6.jar")
}
}

Eclipse Gradle Import with AspectJ Configuration

I have a Gradle project which leverages AOP (from Spring 3.x.x) which I have imported into Eclipse (STS). When I use the Gradle's context menu to refresh dependencies/rebuild source I then have to convert to a AspectJ project in able for me to run my tests correctly (the AspectJ Runtime library isn't on the build path to fulfill the factory-method in the bean definition). I don't have the spring-aspects.jar located anywhere and this deploys to Tomcat without issue (again no aspectJ in the libs/ folder).
<bean id="fooBarAspect" class="foo.Bar" factory-method="aspectOf" >
This process works but is painful as it makes me rebuild twice anytime I need to refresh dependencies and run integration tests.
dependencies {
ajc 'org.aspectj:aspectjtools:1.7.3'
aspects 'org.springframework:spring-aspects:3.2.4.RELEASE'
compile (
'org.aspectj:aspectjrt:1.7.3'
)
}
Thoughts?
For AspectJ:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
ext.aspectjVersion = '1.7.4'
configurations {
ajc
aspects
aspectCompile
ajInpath
compile {
extendsFrom aspects
}
}
compileJava {
sourceCompatibility="1.7"
targetCompatibility="1.7"
doLast{
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(
source:sourceCompatibility,
target:targetCompatibility,
destDir:sourceSets.main.output.classesDir.absolutePath,
maxmem: "512m",
fork: "true",
inpath: configurations.ajInpath.asPath,
aspectPath:configurations.aspects.asPath,
sourceRootCopyFilter:"**/.svn/*,**/*.java",
classpath:"${configurations.compile.asPath};${configurations.aspectCompile.asPath}"){
sourceroots{
sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
}
}
}
}
dependencies {
ajc "org.aspectj:aspectjtools:1.7.3"
compile "org.aspectj:aspectjrt:1.7.3"
aspects group: 'org.springframework', name: 'spring-aspects', version: springVersion
aspectCompile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.0.Final'
aspectCompile group: 'org.springframework', name: 'spring-tx', version: springVersion
aspectCompile group: 'org.springframework', name: 'spring-orm', version: springVersion
}
For Eclipse we have to do bit a manual code:
eclipseClasspath {
withXml { xmlProvider ->
def classpath = xmlProvider.asNode()
def parser = new XmlParser()
classpath.classpathentry.findAll{ entry ->
entry.#kind == 'var' && configurations.runtime.find {entry.#path.endsWith(it.name) && !entry.#path.contains('servlet-api')
}.each { entry ->
def attrs = entry.attributes ?: parser.createNode(entry, 'attributes', [:])
parser.createNode(attrs, 'attribute', [name: 'org.eclipse.jst.component.dependency', value: '../'])
}
}
}
The problem is imo, that the project in eclipse must be marked as aspectj project in order to use the ajc compiler instead of the "normal" compiler. How did you declare the aspectj compilation in your build.gradle file? just adding the aspectj-rt to the compile classpath is definitely not enough.
You can manipulate the eclipse project configuration on xml level using gradle. I did this a long time ago using the withXml hook. have a look at the build.gradle file at
https://github.com/breskeby/gradleplugins/blob/0.9-upgrade/aspectjPlugin/aspectJ.gradle#L29
The way the aspectj eclipse plugin works might be outdated and you probably update it to fit your needs, but you should get the idea.