Adding Jar dependency in gradle custom plugin - groovy

Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set in there system
in MYAPP_HOME page i have a jar at $MYAPP_HOME/lib/mylib.jar
i am writing my own plugin....
I can find the MYAPP_HOME variable is set and fine the jar exists..
How can i add this jar dependency in my custom gradle plugin... ? when user runs my plugin say compileMyplugin my custom gradle plugin need to set the $MYAPP_HOME/lib/mylib.jar jar as compiler dependent
How to do this any one help me ?

The plugin just needs to do:
project.dependencies {
compile project.files("${System.getenv("MYAPP_HOME")}/lib/mylib.jar"))
}
PS: In general, I wouldn't recommend relying on an environment variable and the availability of a Jar on the local file system. Instead, I'd publish the Jar to an artifact repository or put it under source control.

Related

How create pom file in android studio for artifactory?

I have uploaded .aar without pom.xml to artifactory and thus cannot load the library using gradle.
I would be grateful if you tell me or show how it should look inside the pom.xml.
If someone knows how to create the desired content file, then it will be great.
I tried to create pom.xml using the code in gradle below, but it seems to me that this is the wrong option.
task writePom {
doLast {
pom {
project {
groupId 'com.someth.someth'
artifactId 'name'
version '1.1'
url="http://someth.com/artifactory/someth_pr/someth-release.aar"
}
}.writeTo("pom.xml")
}
}
I used url to show where to get my .aar file.
When I put my generated pom.xml file in artifactory and decided to do "Sync now" gradle gave an error:
Failed to resolve: com.someth.someth:name:1.1
From Android Gradle plugin 3.6.0 and higher you can use the afterEvaluate{} publishing which allows you to publish build artifacts to an Apache Maven repository. It includes all the components for each build variant artifact in your app or library module (with the generated pom.xml).
More info you can find in the official Android documentation.
Have in mind that the repositories tag inside the pom.xml file (if you want to import dependencies from a custom source) it's skipped by the Android's gradle tasks for security reasons.
Last, you could use also the old classic way for the publication described by the JFrog official documentation.

Add groovy extention module in runtime

I writing gradle plugin for code generation, and it's use groovy org.codehaus.groovy.runtime.ExtensionModule.
But extensions resolve on gradle (daemon) start stage, and add jar with META-INF/services/org.codehaus.groovy.runtime.ExtensionModule into build script classpath has no effect.
How to register ExtentionModule manually?
I don't believe you can, as it says in the documentation:
to use an extension, it has to be available on classpath, as compiled classes, before the code using it gets compiled

Intellij does not recognize lombok.config when building

I opened the restbucks project with Intellij. I have lombok plugin installed, annotation processing enabled. I am using javac compiler in Intellij settings. I have lombok.config in project root like in git repository, I also tried copying it to src/main/java and src/main/resources but no matter what I try, when I build the project with Intellij, after posting an order, I get:
Argument #0 of constructor [constructor for
org.springsource.restbucks.order.Order, annotations: {interface
com.fasterxml.jackson.annotation.JsonCreator=#com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}]
has no property name annotation; must have name when
multiple-parameter constructor annotated as Creator
Seems like lombok.anyConstructor.suppressConstructorProperties=true has no effect. When I build with maven then it works fine.
When I delete the lombok.config file, Intellij starts showing errors all over the project so the file seems to be recognized by Intellij afterall. But the build doesn't run as expected as posting to orders fails as mentioned above. Does anyone know what's going on here?
Lombok plugin does support lombok.config file.
The lombok.anyConstructor.suppressConstructorProperties is deprecated as per in Lombok doc
BREAKING CHANGE: lombok config key lombok.anyConstructor.suppressConstructorProperties is now deprecated and defaults to true, that is, by default lombok no longer automatically generates #ConstructorProperties annotations. New config key lombok.anyConstructor.addConstructorProperties now exist; set it to true if you want the old behavior. Oracle more or less broke this annotation with the release of JDK9, necessitating this breaking change.
Use the new lombok.anyConstructor.addConstructorProperties in the lombok.config located in the root folder and
also, perform a clean install and then should be fine.

JRebel - sync new gradle jars on classpath

Can jrebel detect a jar file has been added to maven/gradle and then automatically add it my libs folder and add it to the classpath?
For example I'm running IntelliJ and Jetty and I make a gradle change to add a new version of a jar dependency and then click "gradle refresh."
Can jrebel be set up to load that jar? Otherwise this requires a full restart which partially makes jrebel less useful.
The short answer is no.
JRebel works by reloading individual class files, but not whole JARs.
If you add a new dependency or update the version of an existing dependency then it won't get reloaded.
However, if this library you're updating or adding is your own internal library that you build yourself, then it is possible to reload the changes.
In that case you need to build a rebel.xml file into the root of that library jar and configure it to point to the build directory of the library.

Would JRebel work with this project setup?

we have a project where we use Maven to deploy to Tomcat on mvn clean install. I'm fairly new to Java development and finding it difficult to continually wait for install to complete to view changes. I use IntelliJ and I think the class files are only created during mvn install in the target directory.
Is it possible to use JRebel so when I save a file in IntelliJ the compiled class updates Tomcat immediately like they show on the JRebel video?
Thanks
IntelliJ saves the file automatically for you. All you need to do is to recompile the changed classes and these will be picked up by JRebel, given you have included rebel.xml configuration file into the deployed archive.

Resources