I'm really confused about converting an old Google App Engine project to Gradle.
I'm trying to follow the instructions on this page. It advises to start with this build script:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
// url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed)
}
jcenter()
mavenCentral()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
dependencies {
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
compile 'com.google.appengine:appengine:+'
// Add your dependencies here.
}
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
port = 8080 // default
}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
group = 'com.example.appengine' // Generated output GroupId
version = '1.0-SNAPSHOT' // Version in generated output
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
However it doesn't work:
$ gradle appengineRun
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/myproject/build.gradle' line: 32
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find method run() for arguments [build_c1i62diotjttavcmtjg1zqlbd$_run_closure3$_closure5#33f17289] on root project 'myproject' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Shouldn't the dependencies be downloaded to make the custom appengine task configuration work?
Please have a look at the sources of the plugin. When the core plugin is applied it decides whether to apply a flexible or standard appengine plugin. Since there's probably no src/main/webapp/WEB-INF/appengine-web.xml flexible plugin is applied which does not create the extension that fails (FYI, this extension is created here). To fix the problem run:
mkdir -p src/main/webapp/WEB-INF
and then:
touch src/main/webapp/WEB-INF/appengine-web.xml
in console where build.gradle is located. This will solve the problem. Poor documentation :/
Related
When I run gradle sonarqube analysis script from Gitlab ci it give me this exception:
Caused by: java.lang.IllegalStateException: Fail to download sonar-scanner-engine-shaded-9.5.0.56709-all.jar to /builds/sof/sonargitlab/.sonar/cache/_tmp/fileCache2921953783035814983.tmp
Hint:
I am using sonarqube9.5 community edition (running image inside docker)
using also gradle 7.4 and java 11
.gitlab-ci.yml
sonarqube-check:
image: gradle:jre11-slim
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script: gradle sonarqube --stacktrace
allow_failure: true
only:
- merge_requests
- master # or the name of your main branch
- develop
build.gradle:
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id "org.sonarqube" version "3.4.0.2513"
}
sonarqube {
properties {
property "sonar.projectKey", "sof_sonargitlab_AYIwGR4bXnOfnO3zK2VU"
property "sonar.qualitygate.wait", true
}
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:30.1.1-jre'
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
EDIT: This issue was solved by forcing the gradle not to jetify my native library. This is done by adding in gradle.properties
android.jetifier.blacklist = your-causing-issues-library
For more details you can read the official docs or this post
I need to use some native code in a react native project. The native code is provided in a .jar file by the hardware manufacturer. In a clean project (react-native init), with this .jar file inside /android/app/libs folder, this error shows as soon as I try to run "react native run-android".
==============
Error is as follow:
Task :app:javaPreCompileDebug FAILED
6 actionable tasks: 6 executed
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:javaPreCompileDebug'.
Could not resolve all files for configuration
':app:debugCompileClasspath'.
Failed to transform file 'iMagPayV5.1.4.jar' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}
Execution failed for JetifyTransform:
/home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar.
Failed to transform '/home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar' using Jetifier. Reason: 10. (Run with --stacktrace for more details.)
==============
Help is appreciated in advance!!
(Sorry if some information is incomplete).
React Native version 0.60.4 running on Ubuntu 18.04.
I've tried to include some other .jar files in a clean project without inconvenience, but as soon as I include this particular .jar everything blows.
Also, this library is working on an Android Studio project.
The .jar can be found on
https://github.com/GPaoloni/imagpay-framework
android/app/build.gradle looks like this:
...
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
I just want being able to include the .jar library (to be used by a native activity).
==============
Update:
I've tried doing like sugested:
npm install --save-dev jetifier
npx jetify
But the error still the same.
Reading the npm page of jetifier, in the "Usage for jar/zip/aar files" section:
npm install jetifier
npx jetifier-standalone <your arguments here>
Runing this gives me the following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:39)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:443)
at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:49)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:425)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:421)
at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:247)
at com.android.tools.build.jetifier.processor.Processor.transform$default(Processor.kt:234)
at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:157)
at com.android.tools.build.jetifier.standalone.Main$Companion.main(Main.kt:109)
at com.android.tools.build.jetifier.standalone.Main.main(Main.kt)
Try executing these line by line.
1. yarn
2. yarn start
On a new terminal tab
1. react-native run-android
Check whether 'jetifier' running output is displayed on the terminal.
Something similar to this.
"Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag."
If not run these before executing 'react-native run-android'
1. npm install --save-dev jetifier
2. npx jetify
I am using VS Code and installed prettier and format on-save. For some reason, when I saved page, he formatted wrong and I had this error, when discarded changes, it started working well, u can try this, as prevention.
I am trying to get the Gradle Maven Publish Plugin to publish a snapshot version of my Java library to my local Maven repo such that:
The version of the jar is 1.0.0.SNAPSHOT-<timestamp>, where <timestamp> is the current system time in millis (similar to something like System.currentTimeInMillis()); and
I log to STDOUT/console the full name of the jar being published, including the version above; and
A properly-formatted pom.xml is published to Maven local alongside the jar, so that any other Gradle/Maven projects can "pull it down" locally and fetch its transitive dependencies properly
My best attempt so far:
plugins {
id 'java-library'
id 'maven-publish'
}
dependencies {
compile(
'org.hibernate:hibernate-core:5.0.12.Final'
,'com.fasterxml.jackson.core:jackson-core:2.8.10'
,'com.fasterxml.jackson.core:jackson-databind:2.8.10'
,'com.fasterxml.jackson.core:jackson-annotations:2.8.0'
)
testCompile(
'junit:junit:4.12'
)
}
repositories {
jcenter()
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group 'com.me'
jar {
baseName = 'my-lib'
version = '1.0.0-SNAPSHOT'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
However, with this setup, when I run ./gradlew publishToMavenLocal:
I do see the jar being deployed to ~/.m2/repository/com/me/my-lib/ but without a pom.xml and no 1.0.0.SNAPSHOT version appended to it
I don't even know how/where I would append the timestamp onto the version
I don't even know how/where I would do a println(...) to report the full name of the jar being published
Any ideas?
Regarding #3, To install your artifact to a local repository you do not need the maven-publish plugin, rather the maven plugin
See The Maven plugin documentation, specifically the Tasks section and the Installing to the local repository section with it, you can run gradle clean build install
It works for me with a build.gradle file as simple as this
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
Note, if you need to publish something other then the default generated jar then you need to change the archives configuration
Regarding #1 appending the timestamp, move the version line outside the jar clause and change it from
version = '1.0.0-SNAPSHOT'
to
version = "1.0-SNAPSHOT-${System.currentTimeMillis()}"
This is using Groovy GString (AKA string interpolation - note the change from single quotes to double quotes) to append the current time in millis to the version
Last but not least, regarding #2 printing the jar full name append the following to the build.gradle file
install.doLast {
println jar.archiveName
}
Essentially we're appending to the install task (the one executed in the top of my answer) a println of the jar configuration's archiveName (see here if you want something else)
So all in all my build.gradle file looks like this:
group 'com.boazj'
version "1.0-SNAPSHOT-${System.currentTimeMillis()}"
apply plugin: 'java'
apply plugin: 'maven'
install.doLast {
println jar.archiveName
}
Config: Eclipse Neon.1. BuildShip plugin 1.0.21. Gradle 3.2. Tomcat 8.0.33.
Project Structure:
CmbProduct
Common
CommonServer
Model
CaBridge
WebApp
I've got a Web Services application project ("WebApp") which is dependent on multiple other projects. When I use Eclipse WST/WTP to deploy and run WebApp via Tomcat, only Model.jar from "Model" is deployed into the tomcat WST runtime directory as:
.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapp/WEB-INF/lib/Model.jar
All other dependencies for hibernate, etc do seem to be deployed correctly to the same dir above.
This broke when I changed eclipse to use Buildship. Previously I used the Eclipse STS (Spring) plugin and that worked fine.
Here is the web project (WebApp) build.gradle:
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
dependencies {
compile project(":Common")
compile project(":Model")
compile project(":CommonServer")
compile project(":CaBridge")
...
}
eclipse {
wtp {
component {
// Configure the <Context path="..."/> in server.xml
contextPath = '/console'
// dependencies to mark as deployable with lib folder deploy path
libConfigurations += [ project(":MagniCompCommon").configurations.runtime ]
}
}
}
In the above example I first tried without the eclipse.wtp.libConfigurations section. I tried adding that to fix the problem but it has no effect. Yes, I did run 'gradle eclipseWtp', then Add/Remove the 'WebApp' application from its server entry after making that change.
If I go to Eclipse -> WebApp -> Properties -> Java Build Path -> Libraries and look at "Web App Libraries" I see "Model" but not the other projects. If I look at "Project and External Dependencies" I see all projects listed.
Here is the build.gradle for Model (working):
apply plugin: 'eclipse-wtp'
dependencies {
compile project(":MagniCompCommon")
}
Here is build.gradle for Common (not deployed):
apply plugin: 'eclipse-wtp'
dependencies {
//compile project(":MagniCompCommon")
compile project(":Model")
compile("org.glassfish.jersey.containers:jersey-container-servlet:$jerseyGlassfishVersion")
// Required for JAX-RS Client
compile("org.glassfish.jersey.core:jersey-client:$jerseyGlassfishVersion")
}
Here is build.gradle for the top level project (CmbProject):
apply plugin: 'java'
subprojects {
apply plugin: 'java'
apply plugin: 'nebula.provided-base'
apply plugin: 'nebula.optional-base'
sourceCompatibility = JavaVersion.VERSION_1_8
javadoc.enabled = false
sourceSets {
main {
java {
// Define all source dirs - Purpose is to add "src-gen"
srcDirs = ["src/main/java", "src-gen"]
}
}
}
/*
* Repositories used by each subproject must be given below.
* Because each subproject resolves dependencies of other
* subprojects, all subprojects must know all repos.
* In other words, if projectA needs repo "foo.org" and projectB
* depends upon projectA, then projectB needs repo "foo.org" as
* well.
*/
repositories {
maven {
// Local repo for annovention
url uri("$rootDir/MagniCompCommon/repo")
}
mavenCentral()
maven {
url "http://download.java.net/maven/2"
}
maven {
// Texo/EMF
url "https://oss.sonatype.org/content/groups/public/org/eclipse/emf"
}
maven {
// Eclipse
url "https://oss.sonatype.org/content/repositories/public/eclipse"
}
maven {
url "https://repository.jboss.org/nexus/content/groups/public-jboss"
}
maven {
url "http://maven.vaadin.com/vaadin-addons"
}
maven {
url "http://oss.sonatype.org/content/repositories/vaadin-snapshots"
}
maven {
url("http://maven.clapper.org")
}
/*
* -ADD LAST- so that it doesn' override any others
* DynamicReports depends upon JasperReports which lists their own
* bug fixed versions of packages like "com.lowagie:itext:2.1.7.js2"
* This repo provides such patched packages.
*/
maven {
url("http://jasperreports.sourceforge.net/maven2")
}
}
/*
* Variables local to this file
*/
def bouncycastleVersion = "1.54" // Was 1.51
def slf4jVersion = "1.7.19"
def hibernateVersion = "4.3.11.Final"
def texoVersion = "0.9.0-v201501182340"
def emfVersion = "2.11.0-v20150123-0347"
def jnaVersion = "4.1.0"
ext {
/*
* Variables here are used by subprojects
*/
vaadinVersion = "7.6.8" // was 7.6.4
vaadinIconsVersion = "1.0.1"
jerseyGlassfishVersion = "2.23.2" // was 2.22.2
}
dependencies {
/*
* PRODUCT SPECIFIC
*/
compile("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
compile("org.bouncycastle:bcprov-ext-jdk15on:$bouncycastleVersion")
compile("org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion")
compile("com.h2database:h2:1.3.176")
testCompile("org.testng:testng:6.9.4")
/*
* MagniComp common and product
*/
compile("org.simpleframework:simple-xml:2.6.9")
// Logging slf4j API
compile("org.slf4j:slf4j-api:$slf4jVersion")
// Send JCL to slf4j
compile("org.slf4j:jcl-over-slf4j:$slf4jVersion")
// Anything using JUL should defer to slf4j
compile("org.slf4j:jul-to-slf4j:$slf4jVersion")
// Send slf4j to log4j 1.2 for those JARs which use slf4j
compile("org.slf4j:slf4j-log4j12:$slf4jVersion")
// Log4j itself
compile("log4j:log4j:1.2.17")
// Hibernate
// Do not include "hibernate-core" explicitly as hibernate-entitymanager will take care of it
compile("org.hibernate:hibernate-entitymanager:$hibernateVersion")
compile("org.hibernate:hibernate-c3p0:$hibernateVersion")
compile("mysql:mysql-connector-java:5.1.38")
// Texo
compile("org.eclipse.emf:org.eclipse.emf.texo:$texoVersion")
compile("org.eclipse.emf:org.eclipse.emf.texo.server:$texoVersion")
compile("org.eclipse.emf:org.eclipse.emf.texo.xml:$texoVersion")
// Texo dependencies (not automaticly added by texo)
compile("org.eclipse.emf:org.eclipse.emf.common:$emfVersion")
compile("org.eclipse.emf:org.eclipse.emf.ecore:$emfVersion")
compile("org.eclipse.emf:org.eclipse.emf.ecore.xmi:$emfVersion")
// Required by org.eclipse.emf
// Disable because it's causing:
// java.lang.SecurityException: class "org.osgi.framework.BundleReference"'s signer information does not match signer information of other classes in the same package
//compile("org.eclipse.core:org.eclipse.core.runtime:3.7.0")
compile("org.jsoup:jsoup:1.7.2")
// Apache HTTP client
compile("org.apache.httpcomponents:httpclient:4.3.5")
// EventBus and more
compile("com.google.guava:guava:18.0")
// Quartz scheduler
compile("org.quartz-scheduler:quartz:2.2.2") {
exclude group: "c3p0", module: "c3p0"
}
// Java Mail
compile("javax.mail:mail:1.4.5")
// JNA for Common and CaBridge
compile("net.java.dev.jna:jna:$jnaVersion")
compile("net.java.dev.jna:jna-platform:$jnaVersion")
// This package provided by Tomcat or Servlet container
provided("javax.servlet:javax.servlet-api:3.1.0")
}
}
Thanks to some help from the gradle forum I found the solution.
Each project which is a dependency of a WTP project must each have:
apply plugin: 'eclipse-wtp'
Having this only in the WTP project is not enough.
I have created a project in Spring Tool Suite with Spring Boot and Gradle, and I really don't know how to export to make it work.
I don't know much about gradle, just the basics to add dependencies from the maven repository. So in some articles says to apply the application plugin to do the task, but I don't know how to set up the configuration file and how to create the executable.
If anyone could write or link a step by step detailed explanation on how to do it, it would be very much appreciated.
This is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
springBoot {
mainClass = "com.rodamientosbulnes.objetivosventa.Application"
executable = true
}
jar {
baseName = 'objetivosventa'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework:spring-jdbc')
compile('net.sourceforge.jtds:jtds:1.3.1')
compile('org.apache.poi:poi-ooxml:3.13')
compile('com.miglayout:miglayout-swing:4.2')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Build file looks fine, you only need to run gradle build (or Run As -> Gradle -> Gradle build in the STS) to create the runnable jar.
More details about configuration of the gradle plugin are available on spring boot documentation site.
Gradle's application plugin doesn't make a single execitable for you, but it can create a distribution, which includes all the dependencies, jar-artifact for your project and 2 scripts to run it (one batch-file and linex executable).
The main thing you need to know, is that spring-boot plugin already provide all the task from application plugin you may need. All the task you can find here. You need distZip or installDist to package your project to the distribution. This task will create a ready project distribution under your project-folder/build folder. One more task you may find usefull is buildRun which will run you spring-boot application without package it into distribution.