I have the following build.gradle file:
apply plugin:'application'
mainClassName = "MyMain"
allprojects {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.jsoup:jsoup:1.8.3'
}
So when I do gradle run it works perfectly, it uses jsoup and so.
Now, I've imported this project at my Intellij Idea IDE, I created a gradle build run/debug configuration, so when I press the green arrow 'run', it's building the application, but not running it, so I guess it's executing gradle build.
I've searched for an way to run the application, and the Intellij Idea says that I must create a new Application run/debug configuration. I did it, told where my main class was, but when I click run, it tries to make the source code, and claims that it can't find Jsoup for compiling.
How can I mimic gradle run in intellij idea's IDE?
You need to delegate IDE build/run actions to Gradle
Open the gradle window in Intellij. View->Tool Windows->Gradle.
On the right hand side you will see a list of all your gradle tasks. Double click to run or right click and assign a shortcut to any of them.
Look for the Gradle Tool Window. The rest is self-explanatory :)
Do not forget to click "Refresh all Gradle projects" in that tool window each time you change the build script.
Related
When I try to build a kotlin program on android studio, it displays the notification:
*Unable to find Gradle tasks to build: [:].
Build mode: COMPILE_JAVA.
Tests: All.*
This happens when I try to debug or run a code like
fun main(){
println "hello world \n I am Michael Girum."
}
In Android studio, under the project source files, under android>app>src, right click on build.gradle, and click Run 'android'
This will than compile, you can than run the project.
I tried to build an old Android project
classpath 'com.android.tools.build:gradle:2.3.1'
and I solved it by adding a
settings.gradle
with content
include ":app"
From this post (Best way to add Gradle support to IntelliJ Project) I can see that what I need to do is "Add build.gradle in your project's root directory."
I was hoping someone could please explain how I do that in intelliJ? (been searching and reading - still baffled).
I understand a root directory the folder which is the parent for all the project sources, but in standard JavaFX project in intelliJ what is it/how do I find it/assign it, and then how do I add build.gradle?
Note: these steps assume that you are using the latest JDK version (17).
In the project browser, right click on the project name and create a file named build.gradle:
Write a build script. Here is a template for JavaFX applications:
plugins {
id "application" // Use Application plugin
id "org.openjfx.javafxplugin" version "0.0.9" // Use JavaFX plugin
}
mainClassName = "my.package.Application" // Set this to your main class
repositories {
mavenCentral()
}
javafx {
version = "16" // JavaFX Version
modules = [ "javafx.controls" ] // JavaFX modules. Add them to this array.
}
Once you have finished, import the project:
This may take a while depending on your internet speed.
You may have to adjust runtime configurations to use Gradle, but that shouldn't be necessary.
You may encounter the following error:
BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
If that is the case, install Gradle CLI (if you haven't already), and open a command prompt/terminal in the project folder.
Run the following command (works on Windows/Mac/Linux):
gradle wrapper --gradle-version=7.3 --distribution-type=bin
Once you have done that, reload the Gradle project.
I could not resist another GIF:
You may also need to rearrange the source folders:
I apologise for the cat photo, but it was just a placeholder image. I definitely didn't specifically choose it.
While learning android studio from udacity they asked me to download a project; I did so but while I was importing it to android studio I got an error message:
The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3.
Why did I get this error?
If you did not figure this out yet, I am just starting the same project too. I changed the classpath like above. I then found a website to use the latest version of gradle and the plugin. It says "You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file." I did the first one.
Then, I got errors for both build.gradle files in the project and app version. I get this error: Could not find com.android.tools.build:gradle:7.0.3
If you get this error, click the link "Add google Maven repository and sync project". Then you have to click "Do refactor".
Now you come across another error in one of the build.grade files. This stackoverflow link will tell you: Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
Finally, replace testCompile with testImplementation and then you should get BUILD SUCCESSFUL.
The project's Gradle version you're trying to clone is outdated. Change it based on your android studio version.
on your build.gradle(Project) change the version and sync
classpath "com.android.tools.build:gradle:4.1.2"
Got the solution :)
In gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
In build.gradle project level:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In build.gradle module level:
Replace all "compile" with "Implementation" and do other suggested version updated and you are done here :)
Hope this works for you, if yes just press that up button :)
If not getting any solution, the best you can do is copy the "app" folder of your project(using file explorer) and paste it in a newly created project(should be of same name as of your project), in that way you'll get already synced gradle and newly created version of your app.
Because, every important thing in your project is present in its app folder and when you create a new project with same name and copy app folder from your older version of your project, you will have a newer version of your project with all same resources.
Note: You can't move through branches and other commits
I saw this issue several times with Android studio. Below trick worked me the best.
Android Studio suggests to upgrade to newer version, please upgrade it and let it sync
Mostly you would see error message again
Now, Go to File -> Invalidate Caches/Restart
It should work now
If it shows same error then I don't know what to do.
If it shows different error then repeat from step 1 to 3 for new error.
Hope, it helps some..
In my springmvc project, I use gradle as a build tool.
But our FE developers always complain about that why they have to start the project in IntelliJ IDEA, but they don't use the IDE as their editor at all.
so, recently I made a lot of research on running my project from command line.
Please help.
If gradle is used and all is configured well, try gradle run while using the application plugin.
You do need to load the plugin
apply plugin: 'application'
and define the main class of your application
mainClassName = "org.gradle.sample.Main"
Further parameters can be defined as well.
I am adding Espresso to my project in Android Studio. I have installed the Support Repository and in fact have already been using pieces of it. Then I added these dependencies to app/build.gradle per the install instructions:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
in writing my test, auto complete recognizes the existence of the artifacts. But when I run I get this error:
error: package android.support.test does not exist
error: package org.junit does not exist
and a number of other subpackages to these two.
So I removed the two above lines from build.gradle and attempted to add then in the GUI project structure/modules/dependencies
neither 'com.android.support.test.espresso:espresso-core:2.0' nor 'com.android.support.test:testing-support-lib:0.1' appear as options to choose from. However, in my file system there is <sdk>\extras\android\m2repository\com\android\support\test\espresso\espresso-core\2.0\ with the full complement of files including espresso-core-2.0.aar which I am able to open and navigate within it via winzip. In the file system it looks no different than the other libraries installed via SDK Manager with Support Repository.
Why doesn't android studio recognize this library?
Your help is greatly appreciated, no one else that I can find seems to have run into this problem. This is the closest I could find: Why do packages from library module does not exist upon compilation, even when Android Studio shows no errors in code?
I have tried reinstalling Support Repository twice.
I had the same issue and I found that the dependencies with the androidTestCompile are visible only by default in the debug build variant.
You can change the build variant to be tested by adding this to your build.gradle:
android {
...
testBuildType "staging"
}
where "staging" is just an example, you should replace it with one of your build variant.
Remember that only one variant is tested.
More information here https://code.google.com/p/android/issues/detail?id=98326
There are 2 different test dependencies configurations:
testCompile - used by unit test suite (located in src/test folder and invoked by ./gradlew test)
androidTestCompile - used by integration test suite (located at src/androidTest folder and invoked by ./gradlew connectedAndroidTest).
My suspicion is that your test code is in the wrong test suite location
In your case your test code should go into src/androidTest folder and test suite should be executed by running ./gradlew connectedAndroidTest
I had this issue as well and I have my android test cases under src/androidTests as recommended by Google, but this caused problems with build.gradle:
sourceSets {
main {
java.srcDirs = ['src']
}
}
With the above it's trying to compile all my test cases within the normal debug compilation target, which does not include the espresso and other dependencies because they're listed under androidTestCompile.
In the end I fixed this by excluding the androidTest subdirectory from compilation and set the root of androidTest to the appropriate directory.
sourceSets {
main {
java.srcDirs = ['src']
java.excludes = ['androidTest/**']
}
androidTest.setRoot('src/androidTest')
}
I've had the same problem and it was solved by hitting Clean Project from the Build tab in Android Studio.
After hitting Clean Project, watch the Gradle Console for potential errors and if it completes the cleaning successfully, simply go into any one of your test classes and type in "Espresso" and the smart code completion should offer suggestions. Everything should automatically import as you use Espresso after that.
Hope this helps!
My solution was easier and simpler, I just went to Android Studio File>Invalidate Caches/Restart and it worked properly, seems that android studio is keeping some cache that will not clean with Rebuild/Clean.
I encountered this issue while forward-porting one of my apps into a new visual paradigm, and found my app-level build.gradle was missing the following:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
1.Click the drop down menu beside the Run button in the toolbar.
2.Click Edit configuration
3.Now remove all others except app(within Android App) and the Default one.
This worked for me. Hope it helps.