How do you debug a Gradle project with native dependencies in Netbeans? - java

I have a project that requires native libraries to run.
I'm using the Gradle-Support Netbeans plugin.
apply plugin: "java"
apply plugin: "application"
apply plugin: "eclipse"
sourceCompatibility = 1.7
mainClassName = "com.myPackage.MainClass"
if (!project.hasProperty('mainClass')) {
ext.mainClass = mainClassName
}
repositories {
mavenCentral()
maven {
url "http://teleal.org/m2"
}
}
dependencies {
compile group: "com.esotericsoftware.kryo", name: "kryo", version: "2.23.0"
compile group: "net.java.jinput", name: "jinput", version: "2.0.5"
compile group: "org.jcraft", name: "jorbis", version: "0.0.17"
compile group: "org.jdom", name: "jdom2", version: "2.0.5"
compile group: "org.lwjgl.lwjgl", name: "lwjgl", version: "2.9.0"
compile group: "org.lwjgl.lwjgl", name: "lwjgl_util", version: "2.9.0"
compile group: "org.teleal.cling", name: "cling-core", version: "1.0.5"
compile group: "org.teleal.cling", name: "cling-support", version: "1.0.5"
compile group: "xpp3", name: "xpp3", version: "1.1.4c"
compile files("./lib/jars/kryonet-2.21.jar")
compile files("./lib/jars/slick.jar")
compile files("./lib/jars/slick-util.jar")
compile files("./lib/jars/TWL.jar")
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes "Main-Class": project.mainClassName
}
}
run {
configureRun(it)
}
task(debug, dependsOn: 'classes', type: JavaExec) {
configureRun(it)
classpath = sourceSets.main.runtimeClasspath
}
void configureRun (def task){
main = mainClass
task.systemProperty "java.library.path", "./lib/native/"
}
The application will launch fine in run mode but debug mode yields the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':debug'.
> No main class specified

I assume, you are using the application plugin and that is why this configuration for the run task is enough. That is, most likely you should have something like this:
if (!project.hasProperty('mainClass')) {
ext.mainClass = mainClassName
}
run {
configureRun(it)
}
task(debug, dependsOn: 'classes', type: JavaExec) {
configureRun(it)
classpath = sourceSets.main.runtimeClasspath
}
void configureRun(def task) {
main = mainClass
task.systemProperty "java.library.path", "./lib/native/"
}

task(debug, dependsOn: 'classes', type: JavaExec) {
Looks like you're adding an action instead of configuring the the task, all your configuration on the task happens too late, that is at the execution time.
Either that or make sure your main (you must have one somewhere, right? I'm new to this) looks like:
public static void main (String[] args)throws Exception
My research led me to here: (this site may help you with gradle) http://forums.gradle.org/gradle/topics/problem_with_javaexec

Related

Unable to run 'build gradle'

plugins {
id 'java'
id 'com.bmuschko.docker-remote-api' version '6.4.0'
id "io.freefair.lombok" version "5.0.1"
id "java-library"
}
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
archivesBaseName = 'transcription_service_lambda'
repositories {
// mavenCentral()
mavenCentral(
url: "https://repo.maven.apache.org/maven2/"
)
}
dependencies {
compile group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.2.2'
compile group: 'software.amazon.awssdk', name: 's3', version: '2.14.11'
compile group: 'software.amazon.awssdk', name: 'sqs', version: '2.14.11'
compile group: 'com.google.code.gson', name: 'gson', version: '2.3.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
compile group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.856'
compile group: 'com.amazonaws', name: 'amazon-sqs-java-extended-client-lib', version: '1.0.0'
compile(
'software.amazon.awssdk:transcribestreaming:2.15.54',
//'com.amazonaws:aws-java-sdk-dynamodb:1.11.784',
'com.amazonaws:aws-java-sdk-kinesisvideo:1.11.784',
'com.amazonaws:aws-lambda-java-core:1.2.1',
'com.amazonaws:aws-lambda-java-events:3.1.0',
'com.amazonaws:aws-java-sdk-cloudwatch:1.11.784',
'com.amazonaws:aws-java-sdk-apigatewaymanagementapi:1.11.784',
'com.amazonaws:aws-java-sdk-ecs:1.11.784',
'com.amazonaws:amazon-kinesis-video-streams-parser-library:1.0.13',
'org.slf4j:slf4j-api:1.7.24',
'org.slf4j:slf4j-log4j12:1.7.24',
'com.googlecode.json-simple:json-simple:1.1.1',
// need this for our async clients
'software.amazon.awssdk:netty-nio-client:2.13.10',
// need this for logging
'org.apache.commons:commons-lang3:3.6',
// need for argument parsing
'commons-cli:commons-cli:1.4'
)
}
task dockerJar(type: Jar) {
manifest {
attributes 'Main-Classs': 'com.amazonaws.kvstranscribestreaming.KVSTranscribeStreamingDocker'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task copyJarAndNoticesToDocker(type: Copy) {
from dockerJar, "$projectDir/NOTICES"
into "$buildDir/docker"
}
task buildDockerFile(type: Dockerfile) {
from("amazoncorretto:8")
workingDir("/tmp/chime-streaming-transcribe/")
addFile(archivesBaseName + ".jar", "./lib/")
addFile("NOTICES", "./")
}
task buildDockerImage(type: DockerBuildImage) {
dependsOn(copyJarAndNoticesToDocker, buildDockerFile)
images.add('chime-transcribe:latest')
}
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.compileClasspath
}
}
task copyZipFile(type: Copy) {
dependsOn tasks.named("buildZip")
from "$buildDir/distributions/transcription_service_lambda.zip"
into "./infrastructure"
}
task copyCFTemplate(type: Copy){
from "infrastructure/deployment-template.json"
into "$buildDir/distributions"
}
apply plugin: "eclipse"
This is my build.gradle file.
When I run gradle build this is the error that I get
Could not find method compile() for arguments [{group=io.reactivex.rxjava2, name=rxjava, version=2.2.2}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 18.0.2 (Oracle Corporation 18.0.2+9-61)
OS: Mac OS X 12.5.1 x86_64

Gradle can't copy png file in java project

so I've added a png img to my resources, since I want to use it in my project.
But Gradle seems not to let me build the project anymore, it's giving me the following error:
* What went wrong:
Execution failed for task ':processResources'.
> Could not copy file 'C:\workspace\Java\Utilities\EmailService\src\main\resources\img\watermark.png' to 'C:\workspace\Java\Utilities\EmailService\build\resources\main\img\watermark.png'.
Important part of Stacktrace is:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript28.groovy: 4: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" # line 4, column 99.
o¿dHÌIDATx^Ý?╝$Eı┼Ù¥Ö┘]r♫↕$-↓$g%(êê
^
My setup of the project:
build.gradle:
import java.text.SimpleDateFormat
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
ext {
springBootVersion = '2.1.5.RELEASE'
set('springCloudVersion', 'Greenwich.RELEASE')
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'com.palantir.git-version' version '0.11.0'
}
def appName = 'EmailService'
version = '1.1.5'
group = 'dk.xx.email'
if (!hasProperty('mainClass')) {
ext.mainClass = 'dk.xx.email.EmailApplication'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'
apply plugin: 'com.palantir.git-version'
sourceCompatibility = 1.8
repositories {
maven {
credentials {
username XXX
password XXXXXXX
}
url 'http://maven01.local:8080/repository/XX/'
}
mavenCentral()
maven { url 'https://jitpack.io' }
}
bootJar {
baseName = "${appName}"
version = "${version}"
}
dependencies {
compile('net.sf.jt400:jt400:9.5:jt400_jdk8')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile group: 'org.springframework', name: 'spring-mock', version: '2.0.8'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version: '2.1.0.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.1.0.RELEASE'
compile group: 'xx', name: 'NhoData-Entities', version: '0.1.99'
compile group: 'xx', name: 'xx-Entities', version: '2.1.7'
compile('dk.xx.stakeholder.document.archive:DocumentArchive:1.1.10:proxy')
compile group: 'com.itextpdf', name: 'itext7-core', version: '7.0.4'
compile('dk.xx.gui.start:EngagementGui:1.2.2:proxy')
compileOnly("org.projectlombok:lombok:1.18.6")
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// Auto-produce swagger
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
}
task versionTxt() {
doLast {
def versionFile = new File("$projectDir/.ci/version.txt");
versionFile.getParentFile().mkdir();
versionFile.text = """
Version=$version
BuildTime=${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())}
ApplicationName=${appName}
"""
}
}
def dependencyName = "${appName}-proxy-${version}"
task tJar(type: Jar, dependsOn: compileJava) {
archiveName = "${dependencyName}.jar"
classifier = 'proxy'
from(sourceSets.main.output) {
includeEmptyDirs=false
include '**/feign/*'
include '**/domain/*'
include '**/entities/*'
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
}
publishing {
publications {
maven(MavenPublication) {
artifacts {
groupId "${group}"
artifactId "${appName}"
version "${version}"
}
artifact tJar
artifact sourcesJar
}
repositories.maven {
url 'http://maven01.local:8080/repository/xx/'
credentials {
username xx
password xxxxxxxx
}
}
}
}
processResources {
filter(ReplaceTokens, tokens:[gitVersion: gitVersion()])
expand(project.properties)
}
static def buildTime() {
final dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
dateFormat.timeZone = TimeZone.getTimeZone('UTC')
dateFormat.format(new Date())
}
springBoot {
// This statement tells the Gradle Spring Boot plugin to generate a file
// build/resources/main/META-INF/build-info.properties
// that is picked up by Spring Boot to display via /actuator/info endpoint.
buildInfo {
// Generate extra build info.
properties {
def details = versionDetails()
additional = [
by : System.properties['user.name'],
time : buildTime(),
operatingSystem : "${System.properties['os.name']} (${System.properties['os.version']})",
machine : InetAddress.localHost.hostName,
ci_enabled : System.getenv('CI') ? true : false,
ci_buildNumber : System.env.'BUILD_NUMBER' ?: 'UNKNOWN',
ci_jobName : System.env.'JOB_NAME' ?: 'UNKNOWN',
appVersion : version
]
}
}
}
I think it's the filter statement in your processResources config. You're asking Gradle to replace text inside the PNG, but it can't make sense of the text in the PNG (which is because there is no text in it; probably doesn't conform to any reasonable character encoding).

How to include dependencies from tests classes and main executable class in one jar

I am trying to create an executable jar that will launch my selenide test.
TestClass
public class TestClass {
#Test
public void openBrowser(){
System.setProperty("webdriver.chrome.driver", "chrome location");
open("google.com");
}
}
Test Executor
public class TestExecutor {
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { TestClass.class });
testng.addListener((ITestNGListener) tla);
testng.run();
}
}
build.gradle
plugins {
id 'java'
}
repositories {
maven {
url = 'jfrog artifactory url'
}
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task testJar(type: ShadowJar) {
manifest {
attributes 'Implementation-Title': 'Gradle',
'Implementation-Version': project.version,
'Main-Class': 'TestExecutor'
}
from sourceSets.test.output
configurations = [project.configurations.testRuntime]
}
test {
useJUnitPlatform()
}
dependencies {
testCompile 'org.seleniumhq.selenium:selenium-java:3.141.59'
testCompile 'org.apache.poi:poi:4.1.0'
testCompile 'org.apache.poi:poi-ooxml:4.1.0'
testCompile 'org.slf4j:slf4j-simple:1.7.5'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.5.2'
testCompile group: 'com.codeborne', name: 'selenide', version: '5.1.0'
testCompile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.2'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
compile group: 'org.testng', name: 'testng', version: '6.14.3'
}
group 'groupId'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
when building the jar it cannot find the test dependencies.
I have tried adding the testRuntimeClasspath to the jar like so
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
configurations.testRuntimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
but then I receive an error saying Could not find or load main class
I've been going at trying to get this running for 2+ weeks. I don't know what I need to do really because all this is new to me. SEND HELP.
I would recommend you to use Gradle Shadow JAR plugin, instead of creating a JAR with all transitive dependencies youself. They even have the exact example for this case in the docs:
// Shadowing Test Sources and Dependencies
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task testJar(type: ShadowJar) {
classifier = 'tests'
from sourceSets.test.output
configurations = [project.configurations.testRuntime]
}
This way you'll be 100% sure that your final JAR will have all the needed dependencies to run without hassling with collects.
And don't forget to specify the main class, like described here.
shadowJar {
manifest {
attributes 'Main-Class': 'a.b.C' // FQDN!
}
}

Gradle "problem occured evaluating root project. For input string: "=10"

I am trying to install BEAM, an extention on MatSim through the GIT Bash and I keep running into this error. This is exactly what I get:
$ gradle classes
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file 'K:\beam\build.gradle' line: 414
* What went wrong:
A problem occurred evaluating root project 'beam'.
> For input string: "=10"
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 16s
The stacktrace is too big to put in the body, but I could include a screenshot if needed.
This is my build.gradle:
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
buildscript {
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath group: 'kr.motd.gradle', name: 'sphinx-gradle-plugin', version: '1.0.3.Final'
classpath "jp.classmethod.aws:gradle-aws-plugin:0.35"
classpath "com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
classpath 'cz.alenkacz:gradle-scalafmt:1.7.0'
classpath 'com.bmuschko:gradle-docker-plugin:3.6.1'
}
}
plugins {
id "net.ltgt.apt" version "0.5"
id "de.undercouch.download" version "3.2.0"
id "org.scoverage" version "2.5.0"
id 'maven-publish'
}
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'kr.motd.sphinx'
apply plugin: 'application'
apply plugin: 'ManifestClasspath'
apply plugin: 'scalafmt'
apply plugin: 'com.bmuschko.docker-java-application'
group = 'beam'
version = '0.8.0'
description = """"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileScala.options.encoding = 'UTF-8'
def scalaBinaryVersion = "2.12"
def akkaBinaryVersion = "2.5.22"
def circeBinaryVersion = "0.7.1"
def slf4jVersion = "1.7.25"
def kamonVersion = "0.6.7"
def tscfgVersion = "0.9.4"
sourceSets.main.scala.srcDirs = ["src/main/scala", "src/main/java"]
sourceSets.main.java.srcDirs = []
sourceSets.test.java.srcDirs = []
sourceSets.test.scala.srcDirs = ["src/test/scala", "src/test/java"]
sourceSets {
main {
resources {
srcDir "src/main/resources"
}
}
test {
resources {
srcDir "src/test/resources"
}
}
}
if (project.hasProperty('env')) {
sourceSets {
main {
resources {
srcDirs "test/input/" + project.getProperty('env')
}
}
}
}
allprojects {
repositories {
maven { url 'https://download.osgeo.org/webdav/geotools/' }
// maven { url "https://maven.geotoolkit.org/" }
maven { url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases" }
maven { url "https://repo.maven.apache.org/maven2" }
maven { url "https://download.osgeo.org/webdav/geotools" }
maven { url "https://dl.bintray.com/matsim/matsim" }
maven { url "https://maven.conveyal.com/" }
maven { url "https://repo1.maven.org/maven2" }
maven { url "https://download.java.net/maven/2/" }
maven { url "https://people.apache.org/repo/m1-ibiblio-rsync-repository/org.apache.axis2/" }
maven { url "https://dl.bintray.com/andimarek/graphql-java" }
maven { url "https://maven.geo-solutions.it" }
maven { url "https://dl.bintray.com/scalaz/releases" }
mavenLocal()
mavenCentral()
jcenter()
maven { url "http://nexus.onebusaway.org/content/groups/public/" }
maven { url "https://jitpack.io" }
}
}
dependencies {
compile(group: 'com.github.LBNL-UCB-STI', name: 'beam-utilities', version: 'v0.2.4') {
exclude group: 'com.github.LBNL-UCB-STI', module: 'r5'
exclude group: 'org.matsim', module: 'matsim'
}
////////////////////////////
// Java dependencies
////////////////////////////
compile group: 'com.google.inject', name: 'guice', version: '4.1.0'
compile group: 'com.google.inject.extensions', name: 'guice-assistedinject', version: '4.1.0'
compile group: 'com.google.inject.extensions', name: 'guice-multibindings', version: '4.1.0'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.2'
// Apache 2.0
compile group: 'com.univocity', name: 'univocity-parsers', version: '2.8.1'
// LGPL
compile group: 'org.geotools', name: 'gt-main', version: '13.0'
compile group: 'org.geotools', name: 'gt-shapefile', version: '13.0'
compile group: 'org.geotools', name: 'gt-referencing', version: '15.2'
compile group: 'org.geotools', name: 'gt-epsg-wkt', version: '15.2'
compile group: 'org.jfree', name: 'jfreechart', version: '1.0.14'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.4'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-scala_2.12', version: '2.9.4'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'org.jdom', name: 'jdom2', version: '2.0.5'
compile 'com.hubspot.jinjava:jinjava:2.0.5'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.18'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile 'net.sf.supercsv:super-csv:2.4.0'
compile 'org.reflections:reflections:0.9.10'
compile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.2-b01'
compile group: 'com.github.stephenc.eaio-uuid', name: "uuid", version: "3.4.0"
compile "org.jgrapht:jgrapht-core:1.3.0"
compile ('com.github.LBNL-UCB-STI:or-tools-wrapper:7.5-0'){
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
// GPLv3
compile group: 'org.matsim.contrib', name: 'multimodal', version: '0.10.0'
compile group: 'org.matsim.contrib', name: 'bicycle', version: '0.10.0'
compile(group: 'org.matsim.contrib', name: 'decongestion', version: '0.11.0-2018w44') {
exclude group: 'org.matsim', module: 'matsim'
}
compile(group: 'com.github.wrashid.matsim', name: 'matsim', version: '0.10.1-beam-11') {
exclude group: 'log4j', module: 'log4j'
}
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile "ch.qos.logback:logback-classic:1.2.3"
compile "com.typesafe.scala-logging:scala-logging_${scalaBinaryVersion}:3.9.0"
compile "org.slf4j:log4j-over-slf4j:${slf4jVersion}"
compile(group: 'com.github.michaz', name: 'r5', version: '3ab4fa04') {
exclude group: 'ch.qos.logback', module: 'logback-classic'
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
compile "com.sigopt:sigopt-java:4.9.0"
compile("com.uber:h3:3.4.1")
testCompile group: 'junit', name: 'junit', version: '4.8'
testCompile group: 'org.mockito', name: 'mockito-inline', version: '2.27.0'
testCompile group: "org.mockito", name: "mockito-core", version: "2.+"
/////////////////////////////////
// Scala dependencies
/////////////////////////////////
// CORE Scala //
compile "org.scala-lang:scala-library:2.12.10"
compile group: 'org.scala-lang.modules', name: "scala-xml_${scalaBinaryVersion}", version: '1.0.6'
// NEEDED FOR USING REPL //
compile "org.scala-lang:scala-compiler:2.12.10"
// TEST Scala //
testCompile group: 'org.scalatest', name: "scalatest_${scalaBinaryVersion}", version: '3.0.8'
testRuntime "org.pegdown:pegdown:1.4.2" // HTML report for scalatest
// 3rd Party Scala //
compile group: 'org.jliszka', name: 'probability-monad_2.11', version: '1.0.1'
// https://mvnrepository.com/artifact/com.beachape/enumeratum_2.12
compile group: 'com.beachape', name: "enumeratum_${scalaBinaryVersion}", version: "1.5.12"
// https://mvnrepository.com/artifact/com.beachape/enumeratum-circe_2.12
compile group: 'com.beachape', name: "enumeratum-circe_${scalaBinaryVersion}", version: "1.5.14"
compile "com.github.scopt:scopt_${scalaBinaryVersion}:3.7.0"
compile "net.codingwell:scala-guice_${scalaBinaryVersion}:4.1.0" // DI
compile('com.github.carueda:tscfg:v' + tscfgVersion) { // config
exclude group: 'org.scala-lang.modules', module: 'scala-xml_2.11'
}
// https://mvnrepository.com/artifact/io.circe/circe-core_2.12
compile group: 'io.circe', name: "circe-core_${scalaBinaryVersion}", version: circeBinaryVersion
// https://mvnrepository.com/artifact/io.circe/circe-generic_2.12
compile group: 'io.circe', name: "circe-generic_${scalaBinaryVersion}", version: circeBinaryVersion
// https://mvnrepository.com/artifact/io.circe/circe-parser_2.12
compile group: 'io.circe', name: "circe-parser_${scalaBinaryVersion}", version: circeBinaryVersion
compile group: 'com.typesafe.play', name: "play-json_${scalaBinaryVersion}", version: '2.6.3'
compile (group: 'com.github.romix.akka', name: "akka-kryo-serialization_${scalaBinaryVersion}", version: '0.5.2') {
exclude group: 'com.esotericsoftware', module: 'kryo'
}
compile group: 'com.esotericsoftware', name: 'kryo', version: '4.0.2'
compile "com.github.vagmcs:optimus_${scalaBinaryVersion}:3.1.0"
compile "com.github.vagmcs:optimus-solver-oj_${scalaBinaryVersion}:3.1.0"
////////////////////////////////////
///Performance Monitoring (Kamon)///
////////////////////////////////////
compile("io.kamon:kamon-core_${scalaBinaryVersion}:${kamonVersion}")
compile("io.kamon:kamon-scala_${scalaBinaryVersion}:${kamonVersion}")
compile("io.kamon:kamon-akka-2.4_${scalaBinaryVersion}:${kamonVersion}")
compile("io.kamon:kamon-statsd_${scalaBinaryVersion}:${kamonVersion}")
compile "io.kamon:kamon-influxdb_${scalaBinaryVersion}:0.6.9"
compile("io.kamon:kamon-log-reporter_${scalaBinaryVersion}:${kamonVersion}")
/////////////
// Akka Dependencies
////////////
// CORE Akka //
compile group: 'com.typesafe.akka', name: "akka-actor_${scalaBinaryVersion}", version: akkaBinaryVersion
compile group: 'com.typesafe.akka', name: "akka-slf4j_${scalaBinaryVersion}", version: akkaBinaryVersion
//compile group: 'com.typesafe.akka', name: "akka-persistence_${scalaBinaryVersion}", version: akkaBinaryVersion
//compile group: 'com.typesafe.akka', name: "akka-remote_${scalaBinaryVersion}", version: akkaBinaryVersion
compile group: 'com.typesafe.akka', name: "akka-cluster_${scalaBinaryVersion}", version: akkaBinaryVersion
compile group: 'com.typesafe.akka', name: "akka-contrib_${scalaBinaryVersion}", version: akkaBinaryVersion
//compile group: 'org.iq80.leveldb', name: 'leveldb', version: '0.9'
compile group: 'com.typesafe.akka', name: "akka-http_${scalaBinaryVersion}", version: "10.1.8"
compile group: 'de.heikoseeberger', name: "akka-http-circe_${scalaBinaryVersion}", version: "1.25.2"
// TEST Akka //
testCompile group: 'com.typesafe.akka', name: "akka-testkit_${scalaBinaryVersion}", version: akkaBinaryVersion
// 3rd Party Akka //
//compile group: 'org.iq80.leveldb', name: 'leveldb', version: '0.7'
//compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all', version: '1.8'
//compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.5.0'
scoverage "org.scoverage:scalac-scoverage-plugin_${scalaBinaryVersion}:1.3.1", "org.scoverage:scalac-scoverage-runtime_${scalaBinaryVersion}:1.3.1"
compile 'org.apache.commons:commons-compress:1.18'
compile group: 'de.lmu.ifi.dbs.elki', name: 'elki', version:'0.7.5'
compile group: 'com.zaxxer', name: 'nuprocess', version: '1.2.4'
def parquet = "1.10.0"
compile group: 'org.apache.parquet', name: 'parquet-hadoop', version: parquet
compile group: 'org.apache.parquet', name: 'parquet-avro', version: parquet
compile (group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3') {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
// Exclude `ASM` because it is binary incompatible with the one which is gotten from `com.conveyal:kryo-tools`: `org.ow2.asm:asm:5.0.4`
exclude group: 'asm', module: 'asm'
}
}
// Autoformatting using scalafmt
scalafmt {
// configFilePath = ".scalafmt.conf" // .scalafmt.conf in the project root is default value, provide only if other location is needed
}
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails dependencyResolveDetails ->
final requestedDependency = dependencyResolveDetails.requested
if (requestedDependency.name != 'beam-utilities') {
force 'javax.media:jai_core:1.1.3'
}
}
}
exclude group: 'javax.media', module: 'jai_codec'
exclude group: 'javax.media', module: 'jai_imageio'
}
//compileScala.dependsOn(scalafmtAll)
// Task to run scala tests, as Scala tests not picked up by Gradle by default.
task spec(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-h', 'build/scalatest-report', '-oD', '-l', 'beam.tags.ExcludeRegular']
classpath = sourceSets.test.runtimeClasspath
}
build.dependsOn spec
/* //////////////////////////////////////////////////
* Task to run tagged tests.
* Note: use space separated list of tags
* ./gradlew taggedTest -Ptags="beam.tags.Performance beam.tags.Integration"
* /////////////////////////////////////////////////// */
task taggedTest(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o', '-n'] << (project.findProperty('tags') ?: 'org.scalatest.Ignore')
classpath = sourceSets.test.runtimeClasspath
}
task specificTest(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o', '-s'] << (project.findProperty('suite') ?: 'org.scalatest.Ignore')
classpath = sourceSets.test.runtimeClasspath
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Task to run tests periodically on continue integration server.
// ./gradlew periodicTest -Pconfig=test/input/sf-light/sf-light-1k.conf -Piterations=1
////////////////////////////////////////////////////////////////////////////////////////////////////////////
task periodicTest(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o', '-n', 'beam.tags.Periodic'] <<
(project.hasProperty('config') ? '-Dconfig=' + project.findProperty('config') :
(project.hasProperty('iterations') ? '-Diterations=' + project.findProperty('iterations') : '')) <<
(project.hasProperty('config') && project.hasProperty('iterations') ?
'-Diterations=' + project.findProperty('iterations') : '')
jvmArgs = ['-javaagent:build/aspectjweaver-1.8.10.jar']
classpath = sourceSets.test.runtimeClasspath
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
//////////////////////////////////////////////////////////////////////
// Generate config classes reflecting the application.conf file
//////////////////////////////////////////////////////////////////////
task generateConfig {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
}
javaexec {
main = "-jar"
args = [
"build/tscfg-${tscfgVersion}.jar",
"--spec", "src/main/resources/beam-template.conf",
"--scala",
"--pn", "beam.sim.config",
"--cn", "BeamConfig",
"--dd", "src/main/scala/beam/sim/config/"
]
}
}
}
task repl(type: JavaExec) {
main = "scala.tools.nsc.MainGenericRunner"
classpath = sourceSets.main.runtimeClasspath
standardInput System.in
args '-usejavacp'
}
task deleteSf {
doLast {
if (project.file('production/application-sfbay/r5/network.dat').exists()) {
delete 'production/application-sfbay/r5/network.dat'
}
if (project.file('production/application-sfbay/r5/osm.mapdb').exists()) {
delete 'production/application-sfbay/r5/osm.mapdb'
}
if (project.file('production/application-sfbay/r5/osm.mapdb.p').exists()) {
delete 'production/application-sfbay/r5/osm.mapdb.p'
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run Via application plugin
// Note: colon preceding "run" is necessary to only run the main project and not launch the GUI as well.
// ./gradlew :run -PappArgs="['--config', 'production/application-sfbay/beam.conf']"
////////////////////////////////////////////////////////////////////////////////////////////////////////////
mainClassName = "beam.sim.RunBeam"
def myAvailableRam = (System.getenv("MAXRAM") ?: (project.findProperty('maxRAM') ?: "140")).toString().replace("g", "").toInteger()
def getCurrentTimestamp = {
DateTimeFormatter.ofPattern("MM-dd-yyyy_HH-mm-ss")
.withLocale(Locale.US)
.withZone(ZoneOffset.UTC)
.format(Instant.now())
}
def logGC = ["-XX:+PrintGCDetails", "-XX:+PrintGCDateStamps", "-Xloggc:gc_${getCurrentTimestamp()}.log"]
// Use following for remote debug mode
def remoteDebug = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8005"]
def jfr = ["-XX:+UnlockCommercialFeatures", "-XX:+FlightRecorder",
"-XX:FlightRecorderOptions=defaultrecording=true,disk=true,maxage=10h,dumponexit=true,loglevel=info"]
// On the running machine there should be file /usr/lib/jvm/java-8-oracle/jre/lib/jfr/profile_heap_exception.jfc with content from
// https://pastebin.com/N3uuUfPz - it's Java Mission Control with metrics about heap allocation and details about exceptions
def jfrWithMem = ["-XX:+UnlockCommercialFeatures", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints",
"-XX:StartFlightRecording=delay=2s,duration=60m,name=mem_ex,filename=recording.jfr,settings=profile_heap_exception",
"-XX:+FlightRecorder", "-XX:FlightRecorderOptions=disk=true,maxage=10h,dumponexit=true,loglevel=info"]
def jmx = ["-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.port=9005", "-Dcom.sun.management.jmxremote.host=127.0.0.1",
"-Dcom.sun.management.jmxremote.local.only=true", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.ssl=false",
"-Djava.net.preferIPv4Stack=true", "-Djava.rmi.server.hostname=127.0.0.1"]
// UseParallelGC
applicationDefaultJvmArgs = ["-Xmx${myAvailableRam}g", "-Xms${myAvailableRam/2}g",
"-XX:+UseParallelGC", "-XX:+UseParallelOldGC", "-XX:MetaspaceSize=150M", "-Djava.awt.headless=true",
"-Dlogback.configurationFile=logback_prod.xml", "-Xss2048k"] + logGC + jmx
println(applicationDefaultJvmArgs)
run {
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run ExperimentGenerator from Command line
// gradle :execute -PmainClass=beam.experiment.ExperimentGenerator -PappArgs="['--experiments', 'test/input/beamville/example-experiment/experiment.yml']"
// Run R5 GUI server
// gradle --stacktrace :execute -PmainClass=com.conveyal.r5.R5Main -PappArgs="['point','--graphs','production/application-sfbay/r5/']"
////////////////////////////////////////////////////////////////////////////////////////////////////////////
task execute(type: JavaExec) {
jvmArgs = applicationDefaultJvmArgs
if (project.hasProperty("mainClass")) {
main = mainClass
} else {
main = mainClassName
}
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
task matsimConversion(type: JavaExec) {
main = 'beam.utils.matsim_conversion.MatsimConversionTool'
classpath = sourceSets.main.runtimeClasspath
environment "PWD", "na"
if (project.hasProperty("confPath")) {
args Eval.me(confPath)
// if this triggers an error, try
// args "${confPath}"
}
}
task generateDocumentation(type: JavaExec) {
group 'Documentation'
description 'Format the data using Sphinx RST formats'
main = 'beam.docs.GenerateDocumentationTask'
classpath = sourceSets.main.runtimeClasspath
}
tasks.withType(ScalaCompile) {
// Enable Scala warnings output
scalaCompileOptions.additionalParameters = ["-unchecked", "-deprecation", "-feature", "-Xfatal-warnings"]
}
task fmt(dependsOn: scalafmtAll)
task checkScalaFmt() {
doLast {
try {
def workingDir = new File("${project.projectDir}")
def result = 'git diff --exit-code'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() != 0) throw new Exception("""
Please run ./gradlew scalaFmtAll and commit/push the subsequent results to fix this error.
This happened because a git diff yielded a non-zero exit code.
This task was built to be run on the CI server AFTER scalaFmtAll
It should only error if the results of scalaFmtAll resulted in code modifications.
And that would only happen if the committed code is not formatted as expected.""")
} catch (e) {
throw new Exception("An unexpected error was encountered while checking that scalaFmtAll was committed.", e)
}
}
}
docker{
registryCredentials {
url = 'https://index.docker.io/v1/'
username = System.getenv("DOCKER_USER")
password = System.getenv("DOCKER_PASSWORD")
}
javaApplication {
baseImage = 'continuumio/miniconda3'
maintainer = 'LBNL Beam Team'
tag = "beammodel/beam:$version"
}
}
dockerDistTar {
instruction 'RUN apt-get update && apt-get -y install openjdk-8-jdk && rm -rf /var/lib/apt/lists/*'
addFile 'test/', 'test/'
}
dockerCopyDistResources {
from('test/') {
into('test/')
}
}
Specifically line 414 is:
def myAvailableRam = (System.getenv("MAXRAM") ?: (project.findProperty('maxRAM') ?: "140")).toString().replace("g", "").toInteger()
Any help with this would be awesome, none of this is my own code, this is all cloned from a git repository that should be working.

Gradle - Caused by: java.lang.NoSuchMethodError: org.apache.log4j.Logger.getLoggerRepository()Lorg/apache/log4j/spi/LoggerRepository

I have a project in the Eclipse IDE that using the gradle plugin and its working and running successfully within the IDE, However, when I export the project into a jar file using eclipse and run it via cmd, java -jar test1.jar, I get this reoccurring error:
"Caused by: java.lang.NoSuchMethodError:org.apache.log4j.Logger.getLoggerRepository()Lorg/apache/log4j/spi/LoggerRepository;"
From my understanding the log4j-1.2.17.jar file is being retrieved by gradle and is packaged when exported to a runnable jar, using eclipse, but I still get this error.
build.gradle:
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7
repositories {
mavenCentral()
flatDir {
dirs 'F:/flatRepo'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.session:spring-session')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
runtime('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
runtime('org.hsqldb:hsqldb')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
//
// Dimensions dependencies
// log4j
compile group: 'log4j', name: 'log4j', version: '1.2.17'
// https://mvnrepository.com/artifact/javax.mail/mail
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
// https://mvnrepository.com/artifact/commons-codec/commons-codec
compile group: 'commons-codec', name: 'commons-codec', version: '1.4'
// https://mvnrepository.com/artifact/javax.inject/javax.inject
compile group: 'javax.inject', name: 'javax.inject', version: '1'
}
task setHttpProxyFromEnv {
def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']
for (e in System.getenv()) {
def key = e.key.toUpperCase()
if (key in map) {
def base = map[key]
def url = e.value.toURL()
println " - systemProp.${base}.proxy=${url.host}:${url.port}"
System.setProperty("${base}.proxyHost", url.host.toString())
System.setProperty("${base}.proxyPort", url.port.toString())
}
}
}
build.dependsOn setHttpProxyFromEnv

Categories

Resources