diff --git a/app/src/cc/arduino/view/preferences/Preferences.form b/app/src/cc/arduino/view/preferences/Preferences.form
index 797e9d57ded..515c91fe5fb 100644
--- a/app/src/cc/arduino/view/preferences/Preferences.form
+++ b/app/src/cc/arduino/view/preferences/Preferences.form
@@ -480,6 +480,13 @@
+
+
+
+
+
+
+
diff --git a/app/src/cc/arduino/view/preferences/Preferences.java b/app/src/cc/arduino/view/preferences/Preferences.java
index 005d2f83e54..c673986db70 100644
--- a/app/src/cc/arduino/view/preferences/Preferences.java
+++ b/app/src/cc/arduino/view/preferences/Preferences.java
@@ -135,6 +135,7 @@ private void initComponents() {
checkUpdatesBox = new javax.swing.JCheckBox();
saveVerifyUploadBox = new javax.swing.JCheckBox();
accessibleIDEBox = new javax.swing.JCheckBox();
+ loadSketchLibrariesBox = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
scaleSpinner = new javax.swing.JSpinner();
@@ -285,6 +286,9 @@ public void mouseEntered(java.awt.event.MouseEvent evt) {
accessibleIDEBox.setText(tr("Use accessibility features"));
checkboxesContainer.add(accessibleIDEBox);
+ loadSketchLibrariesBox.setText(tr("Use libraries in sketch folder"));
+ checkboxesContainer.add(loadSketchLibrariesBox);
+
jLabel1.setText(tr("Interface scale:"));
jLabel2.setText(tr(" (requires restart of Arduino)"));
@@ -718,6 +722,7 @@ private void autoScaleCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//
private javax.swing.JButton browseButton;
private javax.swing.JCheckBox checkUpdatesBox;
private javax.swing.JCheckBox accessibleIDEBox;
+ private javax.swing.JCheckBox loadSketchLibrariesBox;
private javax.swing.JPanel checkboxesContainer;
private javax.swing.JComboBox comboLanguage;
private javax.swing.JLabel comboLanguageLabel;
@@ -833,6 +838,8 @@ private void savePreferencesData() {
PreferencesData.setBoolean("ide.accessible", accessibleIDEBox.isSelected());
+ PreferencesData.setBoolean("build.load_sketch_libraries",loadSketchLibrariesBox.isSelected());
+
PreferencesData.set("boardsmanager.additional.urls", additionalBoardsManagerField.getText().replace("\r\n", "\n").replace("\r", "\n").replace("\n", ","));
PreferencesData.set(Constants.PREF_PROXY_TYPE, proxyTypeButtonGroup.getSelection().getActionCommand());
@@ -913,6 +920,8 @@ private void showPreferencesData() {
accessibleIDEBox.setSelected(PreferencesData.getBoolean("ide.accessible"));
+ loadSketchLibrariesBox.setSelected(PreferencesData.getBoolean("build.load_sketch_libraries"));
+
saveVerifyUploadBox.setSelected(PreferencesData.getBoolean("editor.save_on_verify"));
additionalBoardsManagerField.setText(PreferencesData.get("boardsmanager.additional.urls"));
diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java
index c2c5b0ff624..0be4b9b40d8 100644
--- a/arduino-core/src/cc/arduino/Compiler.java
+++ b/arduino-core/src/cc/arduino/Compiler.java
@@ -246,7 +246,13 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
addPathFlagIfPathExists(cmd, "-tools", Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toFile());
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
+ if(PreferencesData.getBoolean("build.load_sketch_libraries") == true) {
+ addPathFlagIfPathExists(cmd, "-libraries",Paths.get(sketch.getFolder().getAbsolutePath(),"libraries").toFile());
+ }
+
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
+
+
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder().folder);
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt
index 77d9f136f3d..130fb716ad7 100644
--- a/build/shared/lib/preferences.txt
+++ b/build/shared/lib/preferences.txt
@@ -269,6 +269,10 @@ programmer = arduino:avrispmkii
upload.using = bootloader
upload.verify = true
+# This is true if the arduino IDE will try to load libraries from /libraries
+# This is false by default to maintain backwards compatibility
+build.load_sketch_libraries = false
+
# default port is not defined to prevent running AVRDUDE before Port selected (issue #7943)
#serial.port=
serial.databits=8