Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have project with structure like this:
┌project
│
├── build.gradle
├── module 1
│ │
│ ├── build.gradle
│ ├── module 1.1
│ └── module 1.2
│
└── module 2
│
├── build.gradle
├── module 2.1
└── module 2.2
My problem is that I have builds created for project, module 1 and module 2. But I do not need them, I only need builds from module 1.1, 1.2, 2.1 and 2.2.
In submodules build.gradle:
project(":modules 1") {
ext.buildables = [
project(':modules-1:modules.1.1'),
project(':modules-1:modules.1.2')]
}
project(":modules-1:modules.1.1") {
dependencies {
...
}
}
In root build.gradle:
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
Any thoughts on this?
Edit:
After running gradle build, there is follwoing directory structure:
┌project
│
├── build.gradle
├── build (not wanted)
├── module 1
│ │
│ ├── build (not wanted)
│ ├── build.gradle
│ ├── module 1.1
| | |
│ | └── build
│ └── module 1.2
| |
│ └── build
│
└── module 2
│
├── build (not wanted)
├── build.gradle
├── module 2.1
| |
| └── build
└── module 2.2
|
└── build
How to get rid of these not wanted folders, they all have jars with size of 1kb inside.
Thanks to #Opal for providing link to this discussion.
Added following to allprojects, which skips empty jars.
jar {
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
}
Related
I have a java project in Visual Studio Code with some subprojects:
javaProject
├── README.md
├── build.gradle
├── chronos
│ ├── build.gradle
│ ├── settings.gradle
│ ├── src
├── crate-generator-strategy
│ ├── build.gradle
│ └── src
├── dafne
│ ├── build.gradle
│ ├── settings.gradle
│ └── src
├── gradle.properties
├── hermes
│ ├── build.gradle
│ ├── settings.gradle
│ ├── src
├── meti
│ ├── build.gradle
│ ├── settings.gradle
│ └── src
└── settings.gradle
Under the main dir javaProject there's a dir called .gradle and in that I have different versions of gradle (i.e. 6.4, 7.1.1, 7.4.1)
In my system I have only the 7.4.1 version installed.
------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------
Build time: 2022-03-09 15:04:47 UTC
Revision: 36dc52588e09b4b72f2010bc07599e0ee0434e2e
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.2 (Homebrew 17.0.2+0)
OS: Mac OS X 12.1 x86_64
If I delete the dir, it suddenly reappear with all the versions.
Why there are many versions and not the installed one?
How could I get rid of the old ones?
Thanks,
S.
This is my current setup:
├── src
│ ├── mains
│ │ ├── MainP1.java
│ │ └── MainP2.java
│ └── model
│ ├── Board.java
│ ├── CellStatus.java
│ ├── Coordinate.java
│ ├── exceptions
│ │ ├── BattleshipException.java
│ │ ├── CoordinateAlreadyHitException.java
│ │ ├── InvalidCoordinateException.java
│ │ ├── NextToAnotherCraftException.java
│ │ └── OccupiedCoordinateException.java
│ ├── Orientation.java
│ └── Ship.java
└── test
└── model
├── BoardTest.java
├── CoordinateTestP1.java
├── CoordinateTestP2.java
└── ShipTest.java
I want to be able to run the tests, but VSCode doesn't detect them:
I have tried creating the following .classpath, but still doesn't work:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
</classpath>
I can run the test in the terminal using:
JFILE="Coordinate.java"; JTEST="CoordinateTestP1.java"; JCLASS="CoordinateTestP1"; \
javac -cp ./src/ ./src/model/${JFILE} && \
javac -cp ../herramientas/junit-4.13.1.jar:../herramientas/hamcrest-core-1.3.jar:./src/:./test/ ./test/model/${JTEST} && \
java -cp ../herramientas/junit-4.13.1.jar:../herramientas/hamcrest-core-1.3.jar:./src/:./test/ org.junit.runner.JUnitCore model.${JCLASS}
Update:
There is another more convenient approach: You can configure the classpath of your project if it is a project without build tool support (aka unmanaged folder) by triggering the command Java: Configure Classpath.
You can try right click the folder test and select Add Folder to Java Source Path
I want to import static data in build.gradle file from below class:
public class MyClass{
public static final String PROPERTY_A = "myStringA";
public static final String PROPERTY_B = "myStringB";
}
I saw a project where they used, something like:
import com.example.MyClass
but I couldn't figure out what configurations are to be provided in order to have the visibility of java class from build.gradle.
Any help would be highly appreciated.
You'll want to use buildSrc: https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources
So for your example, your directory structured would look something like:
.
├── build.gradle
├── buildSrc
│ ├── build.gradle
│ └── src
│ ├── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── MyClass.java
│ └── test
│ └── java
│ └── com
│ └── example
│ └── MyClassTest.java
└── settings.gradle
Then you would just import as you have above.
I have an output of npm ls --prod --depth=0 command. I need to extract a root level elements without non-characters prepending them - just the name ":" version.
The tree looks like below:
├─┬ UNMET DEPENDENCY body-parser#1.18.2
│ ├── bytes#3.0.0
│ ├── content-type#1.0.4
│ ├── debug#2.6.9
│ ├── depd#1.1.2
│ ├── http-errors#1.6.2
│ ├── iconv-lite#0.4.19
│ ├── on-finished#2.3.0
│ ├── qs#6.5.1
│ ├── raw-body#2.3.2
│ └── type-is#1.6.15
├── UNMET DEPENDENCY bootstrap#3.3.7
├─┬ UNMET DEPENDENCY cfenv#1.0.4
│ ├── js-yaml#3.7.0
│ ├── ports#1.1.0
│ └── underscore#1.8.3
├─┬ UNMET DEPENDENCY cloudant#1.10.0
│ ├── async#2.1.2
│ ├── cloudant-nano#6.7.0
│ ├── debug#3.1.0
│ └── request#2.88.0
├─┬ UNMET DEPENDENCY cookie-parser#1.4.3
│ ├── cookie#0.3.1
│ └── cookie-signature#1.0.6
├── UNMET DEPENDENCY es6-promise#4.2.4
├── UNMET DEPENDENCY express#^4.13.4
├── UNMET DEPENDENCY express-async-handler#1.1.4
├─┬ UNMET DEPENDENCY express-handlebars#3.0.0
│ ├── glob#6.0.4
│ ├── graceful-fs#4.1.11
│ ├── handlebars#4.0.11
│ ├── object.assign#4.1.0
│ └── promise#7.3.1
├─┬ UNMET DEPENDENCY express-session#1.15.6
│ ├── cookie#0.3.1
│ ├── cookie-signature#1.0.6
│ ├── crc#3.4.4
│ ├── debug#2.6.9
│ ├── depd#1.1.2
│ ├── on-headers#1.0.1
│ ├── parseurl#1.3.2
│ ├── uid-safe#2.1.5
│ └── utils-merge#1.0.1
├─┬ UNMET DEPENDENCY express-ws#3.0.0
│ └── ws#2.3.1
├─┬ UNMET DEPENDENCY isomorphic-fetch#2.2.1
│ ├── node-fetch#1.7.3
│ └── whatwg-fetch#2.0.3
├── UNMET DEPENDENCY jquery#3.3.1
├── UNMET DEPENDENCY moment#2.20.1
├─┬ UNMET DEPENDENCY morgan#1.9.1
│ ├── basic-auth#2.0.1
│ ├── debug#2.6.9
│ ├── depd#1.1.2
│ ├── on-finished#2.3.0
│ └── on-headers#1.0.1
├─┬ UNMET DEPENDENCY multer#1.3.0
│ ├── append-field#0.1.0
│ ├── busboy#0.2.14
│ ├── concat-stream#1.6.0
│ ├── mkdirp#0.5.1
│ ├── object-assign#3.0.0
│ ├── on-finished#2.3.0
│ ├── type-is#1.6.15
│ └── xtend#4.0.1
├─┬ UNMET DEPENDENCY passport#0.3.2
│ ├── passport-strategy#1.0.0
│ └── pause#0.0.1
├─┬ passport-http#0.3.0
│ └── passport-strategy#1.0.0
├─┬ UNMET DEPENDENCY sha1#1.1.1
│ ├── charenc#0.0.2
│ └── crypt#0.0.2
├─┬ UNMET DEPENDENCY socket.io#2.0.4
│ ├── debug#2.6.9
│ ├── engine.io#3.1.4
│ ├── socket.io-adapter#1.1.1
│ ├── socket.io-client#2.0.4
│ └── socket.io-parser#3.1.2
├── UNMET DEPENDENCY vcap_services#0.3.4
├─┬ UNMET DEPENDENCY watson-developer-cloud#2.42.0
│ ├── async#2.6.0
│ ├── buffer-from#0.1.1
│ ├── cookie#0.3.1
│ ├── csv-stringify#1.0.4
│ ├── extend#3.0.1
│ ├── isstream#0.1.2
│ ├── object.omit#3.0.0
│ ├── object.pick#1.3.0
│ ├── request#2.83.0
│ ├── solr-client#0.7.0
│ ├── vcap_services#0.3.4
│ └── websocket#1.0.25
└─┬ UNMET DEPENDENCY xlsx#0.12.13
├── adler-32#1.2.0
├── cfb#1.0.8
├── codepage#1.13.1
├── commander#2.15.1
├── crc-32#1.2.0
├── exit-on-epipe#1.0.1
└── ssf#0.10.2
The below code parses this tree and extracts all the rows instead of the root ones:
npm ls --prod --depth=0 | sed -e 's/[^a-zA-Z0-9#.\\/ -]//g' -e 's/^[ \\t#]*//' | sed '/deduped/d' | sed -e 's/UNMET DEPENDENCY //' | sed -e 's/UNMET OPTIONAL DEPENDENCY //' | sed '1 d' | sed -e 's/#/:/g' -e 's/^:/#/' | sort | uniq
The expected result the list of root level elements
body-parser:1.18.2
bootstrap:3.3.7
cfenv:1.0.4
cloudant:1.10.0
cookie-parser:1.4.3
express:4.13.4
express-async-handler:1.1.4
express-handlebars:3.0.0
express-session:1.15.6
express-ws:3.0.0
isomorphic-fetch:2.2.1
jquery:3.3.1
moment:2.20.1
morgan:1.9.1
multer:1.3.0
passport:0.3.2
passport-http:0.3.0
sha1:1.1.1
socket.io:2.0.4
vcap_services:0.3.4
watson-developer-cloud:2.42.0
xlsx:0.12.13
The actual result - the list of all elements from the tree in name:version format. I need to have it working on at least RHEL GNU/Linux and Ubuntu.
One more condition is not to use the expressions with tree symbols like below:
sed -e 's/^├─┬ //;s/^├── //;s/^─┬ //;s/^└─┬ //;s/^└── //;' Running such expression from Java won't work
Thank you in advance!
sed -E '/^(├|└─)/!d;s/^(├|└─).*UNMET DEPENDENCY ([a-zA-Z0-9_\.-]+)#\^?(([0-9]\.?)+)/\2:\3/g'
gives on Ubuntu the following output:
body-parser:1.18.2
bootstrap:3.3.7
cfenv:1.0.4
cloudant:1.10.0
cookie-parser:1.4.3
es6-promise:4.2.4
express:4.13.4
express-async-handler:1.1.4
express-handlebars:3.0.0
express-session:1.15.6
express-ws:3.0.0
isomorphic-fetch:2.2.1
jquery:3.3.1
moment:2.20.1
morgan:1.9.1
multer:1.3.0
passport:0.3.2
passport-http:0.3.0
sha1:1.1.1
socket.io:2.0.4
vcap_services:0.3.4
watson-developer-cloud:2.42.0
xlsx:0.12.13
As requested in the comments: With the following sed-command root items with UNMET OPTIONAL DEPENDENCY or without any UNMET... will be listed in the same format:
sed -E '/^(├|└─)/!d;s/^(├|└─)[^a-zA-Z0-9_]+ ?(UNMET (OPTIONAL )?DEPENDENCY)? ?([a-zA-Z0-9_\.-]+)#\^?(([0-9]\.?)+)/\4:\5/g'
I am migrating Java 8 application to JDK11 (early access). New code suppose to be a module. It read an error message from property file in Java8, but return 'null' in Java 11. Any help how to load/read resourceInputStream from /src/resources/messges/myerrors.properties
Any help appreciated.
tree:
├── build.gradle
├── out
│ └── production
│ ├── classes
│ │ ├── com
│ │ │ └── acme
│ │ │ └── Main.class
│ │ └── module-info.class
│ └── resources
│ └── messages
│ └── mymessages.properties
├── settings.gradle
└── src
├── main
│ ├── java
│ │ ├── com
│ │ │ └── acme
│ │ │ └── Main.java
│ │ └── module-info.java
│ └── resources
│ └── messages
│ └── mymessages.properties
└── test
├── java
└── resources
Java:
package com.acme;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class Main {
public static void main(String args[]){
Main m=new Main();
m.process();
}
void process(){
PropertyResourceBundle prb= (PropertyResourceBundle)ResourceBundle.getBundle("messages.mymessages",Locale.getDefault());
String key="key1";
String value= prb.getString(key);
System.out.println(key+":"+value);
}
}
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name messages.mymessages, locale en_US
at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2045)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1679)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1572)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1546)
at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:914)
at resource.main/com.acme.Main.process(Main.java:13)
at resource.main/com.acme.Main.main(Main.java:10)
For the code above solution is: "--class-path ./out/production/resources". I figured out. Also, another variation is this. I have a set of JUnits. During test code need to generate error message from /src/main/resources/messages/mymessages.properties. However, the test wasn't able to "see" resources from "main". After 1 day of trying different combinations solution was: "--module-path ...pathTotestClassesOrOtherProductionClasses;$buildDir/resources/main;$buildDir/resources/test;". So you need to add ".../resources/main" as module path