I am building a Gradle plugin that checks the dependencies of an app for a particular version of my library, and downloads a configuration file specific to that version.
Question: How can a plugin get all/some dependencies' versions of the project into a string?
In a way, I want to have a task which consumes (and then parses) the screen output of the androidDependencies task.
What have I tried:
Read the project's dependencies as they are. Didn't work as I could only get the dependencies before they are resolved into actual versions (the '+' version, or some other resolve strategy the app might exhibit).
Reverse-engineered the androidDependencies task to see how I could do the same, and instead of println, append to a string. Too time-consuming, and didn't feel like the right approach anyway.
From within a task in my plugin, spawn a process that executes ./gradlew dependencies and directs the output of that process into a string. This works but launching a new gradle daemon takes time, and the task finishes in about 5 seconds instead of what should be instantaneous.
Is there a better solution?
Related
I am an Eclipse/STS user/developer, now trying to use IntelliJ Idea (CE)
2020.2.(1,2,3)
For a project based on Gradle, how spring-integration, when I open the IDE it happens the following
Ok, let the IDE load the project ... but
From above, that is the problem, I don't want that the IDE starts automatically to build/rebuild the project. I just need, open the project and that's all.
Observation: for example in Eclipse/STS exists the option to disable Build Automatically
I did do a research in the Web and I read the following posts and questions:
How to disable automatic gradle builds?
IntelliJ IDEA “Build project automatically” apparently not working
Intellij IDEA Java classes not auto compiling on save
Sadly the dialog options were changed but ...
Therefore:
From above, seems nothing to do.
Observation: from above observe the Build project automatically option is disabled
Even with that disabled and after to restart the IDE, I must always stop manually the build process
So what is missing? or Do I need a special extra plugin to accomplish my goal?
The images that you show indicate that you are building with Gradle, but the Compiler option that you disable is relevant for building projects with Idea not with Gradle.
For the 2020.2 version, you need to do the following:
Open the Setting > Build Tools page.
Disable the "Reload changes in build scripts" option.
This way you can manually control the reload. When you change the build script, you will see a small gradle icon in the right side of the editor.
For more info, refer to the IntelliJ IDEA help > Gradle section.
https://www.jetbrains.com/help/idea/work-with-gradle-projects.html#auto_reload
There are two different things in IntelliJ's Gradle support that sometimes confused: sync and build. Your pictures demonstrate sync process (note caption on the toolwindow). Word build is kind of misleading here.
What is sync? In gradle we use Groovy to define the build procedure. Groovy is an imperative programming language, so it's hard to predict resulting dependencies graph without actually executing the script. During the sync Idea executes configuration phase of gradle build (one that builds dependency graph), and obtains configured objects from the Gradle daemon. This information is used to setup project in the IDE: modules, libraries, dependencies, which sources are test, which are prod, etc.
Actual build is not happening during sync. You can convince yourself by adding syntax error to any source file, and observe that the sync succeeds. But build will fail if you invoke it.
In answer to the original question: you can't disable automatic build, because it is not enabled.
Is it possible to disable sync in Gradle project? Short answer - no. If you need a code browser, which is not required to understand all the cross-references in the source code, IDEA is not the best choice probably.
TL;DR;
Without sync IDE does not know which files are sources, and which are not. IDEA cannot open folders. It only can open projects. Good thing is that module can contain folder. So you can do the following: File | New | Project. Select Empty project, Next, select some random folder outside the source folder you want to open, Finish.
Then add new module:
Select Java in the left panel, everything else keep default, Next, Finish. Then in new module remove existing content root, and add folder with sources as new content root
Resulting project is mostly useless. Tons of red code (at least, unresolved symbols from external libraries), no inspections, no navigation, no sense. But it might be useful in some rare situations indeed.
I have a project made with Android Studio 3.0 with coworkers. There are so many Tasks for installing the application. After I finished updating the Android Studio from 3.0 to 3.3.2, almost tasks in project(root)>tasks are not visible. Checkout my gradle project below.
3.0 :
my-project
ㄴmy-project (root)
ㄴTasks
ㄴandroid
ㄴbuild
ㄴbuild setup
ㄴhelp
ㄴinstall
ㄴother
ㄴverification
ㄴmy-module-one
ㄴTasks
ㄴandroid
ㄴbuild
ㄴhelp
ㄴinstall
ㄴother
ㄴverification
ㄴmy-module-two
...
3.3.2 :
my-project
ㄴmy-project (root)
ㄴTasks
ㄴbuild setup
ㄴhelp
ㄴother
ㄴmy-module-one
ㄴTasks
ㄴandroid
ㄴbuild
ㄴcleanup
ㄴhelp
ㄴinstall
ㄴother
ㄴverification
ㄴmy-module-two
...
I can check some tasks are not visible and suddenly the "cleanup" thing appears in every modules. How can i solve it and What's the reason of these problems.
Had the same problem: after import from GitHub there weren't any Gradle tasks in Android Studio. Spent hours on solving this issue but nothing helped. Only these steps solved problem in my case:
In Android Studio go to File -> Settings... -> Experimental and uncheck the Do not build Gradle task list during Gradle build checkbox.
Delete cloned project and clone it again (if some of required files like keystore properties are not present, add them and do File -> Invalidate Caches / Restart).
Android Studio 4.2 has a new experimental feature for Gradle, which is Do not build Gradle task list during Gradle sync. Unfortunately, it comes checked (on) by default, and results in the Gradle task list not being visible in the Gradle view. This because the Gradle task list is not even being generated. However, it leaves many of us wondering what happened to the Gradle task list.
You can go to Settings (e.g., File -> Settings on windows, Preferences -> Settings on mac) and go to Experimental. There you can uncheck the new option.
Then just click on Sync Project with Gradle Files and the Gradle task list will be generated and visible again.
Accroding to this link
Behavior changes:
Lazy task configuration: The plugin now uses Gradle’s new task creation API to avoid initializing and configuring tasks that are not required to complete the current build (or tasks not on the execution task graph). For example, if you have multiple build variants, such as “release” and “debug” build variants, and you're building the “debug” version of your app, the plugin avoids initializing and configuring tasks for the “release” version of your app.
Calling certain older methods in the Variants API, such as variant.getJavaCompile(), might still force task configuration. To make sure that your build is optimized for lazy task configuration, invoke new methods that instead return a TaskProvider object, such as variant.getJavaCompileProvider().
If you execute custom build tasks, learn how to adapt to Gradle’s new task-creation API.
I have a alot of jobs on Hudson, most of which are really small and consist of just a few modules. But one is big and consist of several modules.
When ever I make a commit to our subversion repository for any of those several modules in that big job, Hudson builds the entire job instead of just the module that have changed.
It doesn't matter if I just scm-polling or a subversion hook, the result is the same.
It seems to me like it would be better if the modules where built instead of the jobs since the other modules in other jobs have dependencies to the modules and not to the jobs.
Can this be configured or do I have to create several jobs instead of the big one? And if so, can I configure the big job to never build when any of it's modules are being triggered but still build when it's own pom.xml is changed?
Thanks.
Hudson has an "Incremental Build" option in the Maven area of the job configuration.
It's hidden in the "Advanced" area.
You could make use of the reactor plugin. For example:
mvn reactor:make-scm-changes
This will only build those modules that have been changed in the SCM. Follow the link for other examples.
Doesn't your compiler offers you the incremental compile option? The java 1.6 compiler usually searches for class and source files and decides using the timestamp to determine whether to use the source or class file. Just leave out the clean goal when building your code.
Another option would be to first run a batch/shell script to determine what files changed and delete the corresponding class files so that the compiler incrementally builds the class files that are missing.
I find myself often running the same goals (clean install) of different, interdependent maven projects in Intellij IDEA one after another.
Does anyone know of a way to configure something like a maven goal combination, ideally such that you configure a button in IDEA's task bar that you can hit to execute these goals in sequence? Possibly even with a keyboard short cut?
Similar things might be achieved with a maven run configuration, but then IDEA wouldn't automatically be aware of the changes the run does to the project's file system resources.
Cheers,
Johannes
Easy solution for me was to create a Run Configuration (type=Maven) per module, putting multiple goals (e.g: clean install) as cmd line for each of them, then linking them up into a chain, by adding an appropriate one under the "Before launch" section.
You can link up the last of the chain as a "Before launch" for the actual app Run.
Then you can, if required, just restart a running instance if your app which will rebuild your maven projects in order, and start the app again.
I frequently run a clean install of my maven aggregator project from the command line while it is open in IntelliJ. In my experience the IDE seems to handle this quite well.
when you open the MVN - 'Run Anything' appears - beside that there is a PROJECT drop down, from which you can select for which project you want to run the maven command.
I'm using PMEase QuickBuild to perform automated builds of our Maven2 projects and a nightly sanity test to ensure nothing is broken.
The test needs to untar packages which are created by the automated Maven2 projects. The problem is that the package names change frequently due to project versions being incremented all the time.
Does anyone know how I can configure QuickBuild to pick up the version (ideally from the POM file of the individual components), if this is possible at all?
I don't know if this is an option for you but it looks like you can do it the other way around. Quoting Build with Maven:
Control build version
If you want to control the build
version from QuickBuild side, please
follow below steps:
Change the POM file and define the project version as
${buildVersion}. Do not forget to
commit the file into your SCM after
change.
Define a build property like below when define the Maven build
step:
buildVersion=${build.version}
There are maybe other options but I must admit that my knowledge (zero) of QuickBuild is very limited
I created a work around to this issue by having QuickBuild execute a shell script which did the untarring by using wildcards, similar to the following (to avoid computing the exact version):
tar xzf filename-*.tar.gz
I couldn't figure out how to do this in QuickBuild, so I offloaded the work to the shell script.