This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 194036 - Convenient way to toggle maven --offline
Summary: Convenient way to toggle maven --offline
Status: REOPENED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.0
Hardware: All All
: P3 normal with 2 votes (vote)
Assignee: Tomas Stupka
URL:
Keywords: UI
Depends on: 198358
Blocks:
  Show dependency tree
 
Reported: 2011-01-05 03:40 UTC by _ tboudreau
Modified: 2016-07-10 19:29 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Patch adding a Maven Offline Mode action to the Run menu (12.20 KB, patch)
2011-01-05 03:40 UTC, _ tboudreau
Details | Diff
Build log (52.68 KB, text/plain)
2011-01-12 16:52 UTC, _ tboudreau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 2011-01-05 03:40:37 UTC
Created attachment 104712 [details]
Patch adding a Maven Offline Mode action to the Run menu

I'm working in a codebase with 66 maven projects and 9 repositories defined in the parent POM.  Building this without using

mvn --offline

is fairly impractical (66 * 9 = 594 http connections to servers with various latency for one full build when 99% of the time, nothing has changed, and most connections are making the same request).

This means, of course, that whenever there *is* a dependency change, I *do* want Maven online for one build of one subproject.  Which is the following gestures in NetBeans:
 - Click Tools
 - Click Options
 - Wait for initialization
 - Click Miscellaneous
 - Click Maven
 - Give focus to the options check box
 - Type --offline (ideally not blowing away other settings, though often I do - I use -DargLine= to tell a custom JUnit TestRunner not to run certain time-consuming tests when invoked from the IDE)
 - Click OK

This is way too many gestures for something simple and commonly needed.

I'm attaching a patch which adds a checkbox action to the bottom of the Run menu;  the action is only visible when a Maven project is active.

Apologies for the complexity - BooleanStateAction does not work as DynamicMenuContent, and DynamicMenuContent.HIDE_WHEN_DISABLED does not work for BooleanStateAction;  I looked briefly at the myriad annotations we now have for actions and it wasn't at all obvious what combination would actually do something useful.
Comment 1 Jesse Glick 2011-01-12 03:56:38 UTC
I don't think UI changes are being accepted for 7.0 at this point. Could be implemented as a separate module. (Use NbMavenProject.class as the marker.)


BTW @ActionRegistration ought to work correctly here. (Since the action implements DynamicMenuContent it will not be eagerly loaded.)


Action should likely be enabled iff a Maven project is open; enabling according to selection is not natural in this case I think.


Whether --offline is really needed for routine development is another question:

1. If you already have an artifact in your local repository, Maven does not need to make any network connection - it just uses it. So if you have an explicit version declaration (which Maven 3.0 requires) and you have not changed it recently, there is no need for any remote operation.

2. Maven 3.0 keeps track of when it last checked a remote repository for things like new versions of an artifact. It will not make a network connection unless it has been some time (a day, IIRC) since it last checked.

3. You are strongly advised to use a repository manager, either running on localhost or on a team development server with good connectivity.

I would not be inclined to add to the UI unless there is a compelling use case for switching on and offline frequently.
Comment 2 _ tboudreau 2011-01-12 16:52:43 UTC
Created attachment 104930 [details]
Build log

> Whether --offline is really needed for routine development is another question:
> 1. If you already have an artifact in your local repository, Maven does not
> need to make any network connection - it just uses it. 

Not my experience in practice - I'll attach a typical build output w/o --offline.  Maybe something screwed up in my master pom.xml, but I can't imagine what.

Multiply the attached * 66 to get an idea of the experience of doing a full build w/o --offline, and bear in mind that each "Downloading..." stalls things for a while.

> 2. Maven 3.0 keeps track of when it last checked a remote repository for things
> like new versions of an artifact. It will not make a network connection unless
> it has been some time (a day, IIRC) since it last checked.

Yes, this just means once in a while it's even worse.

> 3. You are strongly advised to use a repository manager, either running on
> localhost or on a team development server with good connectivity.

Got one;  but connectivity is less than ideal - we're a very geographically distributed company, so it's always going to be lousy for someone (particularly connectivity in China).

> I would not be inclined to add to the UI unless there is a compelling use case
> for switching

Then, any chance of exposing an API to toggle this setting so that I could write a module which adds the action w/o hackery?
Comment 3 Jesse Glick 2011-01-12 17:48:18 UTC
(In reply to comment #2)
> I'll attach a typical build output w/o --offline.

Assuming you have built these projects at least once before, so that the required artifacts are in your local repo, this should not happen. Something is wrong in your setup. See:

https://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html#Maven3.xCompatibilityNotes-CachingofArtifactResolutionErrors
https://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html#Maven3.xCompatibilityNotes-ResolutionfromLocalRepository

>> 3. You are strongly advised to use a repository manager, either running on
>> localhost or on a team development server with good connectivity.
> 
> Got one;  but connectivity is less than ideal

That is why running e.g. Nexus on localhost helps. You can always feel free to blow away ~/.m2/repository/ without fear of triggering new massive downloads.

> any chance of exposing an API to toggle this setting

Don't think any is needed - you can access any NbPreferences node you like.
Comment 4 Jesse Glick 2011-05-05 17:50:51 UTC
Bug #198358 would make it easier to get to Maven global settings. Could then just have a checkbox there.
Comment 5 _ tboudreau 2011-05-05 17:55:18 UTC
Still would prefer it to be something you can toggle in a simple way - I typically have other arguments I want to keep passing to maven, so having to go in and tweak this line every time I've added one library I don't have locally to a project, and then tweak it again so the next build doesn't try to download the entire internet is a lot of gestures for something very commonly needed.
Comment 6 Jesse Glick 2011-05-05 18:41:40 UTC
Again, I think something is wrong in your setup; a subsequent build with unchanged dependency declarations should not be attempting to make any network connections.
Comment 7 retobg 2013-04-18 04:15:03 UTC
I'm very much looking forward to this feature. I don't just enable offline because of speed but also because I sometimes need to make sure my local modified version is used even if in between the SNAPSHOT-versions on the remote repository are newer.
Comment 8 _ tboudreau 2013-04-18 05:57:40 UTC
Yeah, the big thing that this issue addresses is Maven's SNAPSHOT handling, which results in download-the-internet builds every so often.  Try that behind the great firewall of China sometime :-)

The other issue it addresses is where you're not actually online, and Maven helpfully deletes your only local copy of a snapshot dependency before it discovers it can't download a new one.
Comment 9 markiewb 2013-05-10 17:02:21 UTC
@Milos: Still in state "STARTED" since 2011?
Comment 10 _ tboudreau 2013-05-10 18:55:19 UTC
Don't blame Milos - it's in the state STARTED because I wrote a patch for it and set the status that way.

It is, however, up to him and probably some human interface people whether it ever becomes FINISHED :-)
Comment 11 lucrus 2013-08-31 06:58:58 UTC
For those out there using NB on Linux like me, here is the workaround I use to speed up --offline toggling.

I have this $HOME/bin/mvn script:

#!/bin/bash

/usr/bin/mvn --offline $*
#/usr/bin/mvn $*

and $HOME/bin is in my $PATH before /usr/bin (default in Ubuntu after you create your $HOME/bin folder).

Now editing that script and switching the commented line is all it takes to toggle --offline. You can keep the script code open in a NB editor window of course. Not the ideal solution, but more handy than the NB options window I think.

I'm quite sure the same can work in OSX. Maybe Windows too can handle something similar.
Comment 12 retobg 2013-11-07 17:47:36 UTC
The patch has been there for years. Please at least tell us you wont fix it so we stop checking whenever a build is taking insanely long because the snapshots are refreshed on a mobile connection (and no just abort is a bad idea as this is likely to result in a broken jar in the local repo) -  but don't let us hang...
Comment 13 Milos Kleint 2013-11-07 18:25:40 UTC
would the offline property in settings.xml work for you?

http://maven.apache.org/settings.html#Simple_Values


the problem with maven specific main menu item is that it's in the main menu basically.

still I'm not seeing repeated downloads of snapshots during builds locally. Maybe the update policy on the repository definitions should be changed (or made customizable for easy switching)
Comment 14 retobg 2013-11-07 19:51:52 UTC
The offline property in settings.xml with an easy way to toggle would be a suboptimal solution. It's not ideal as it side effects on when I call maven on the command line where I can easily switch between adding an omitting the -o switch.

I think it would be nice to have a netbeans specific offline setting. As I basically only use maven projects I'm not sure if an offline mode could be useful in other contexts too. Having Netbeans checking for updates and sending feedback is also not so nice on an expensive roaming data connection. So the offline button could do a bit more than what described by tboudreau to legitimate a prominent position say in the status bar (thinking at the place where update notification show up is called).

I really don't think this can reasonably be solved by some update policy. The idea of snapshots is that I always have the latest version so if it can (i.e. when the download time is shorted than my patience span) it should check the remote repo and see if a newer version is there. If I change my settings in a way this doesn't happen I would have to use -U,--update-snapshots to make sure I get the update my colleague just deployed. But this option is as hard to set as the --offline setting, also despite its name this option seems to force checks both updates and releases.
Comment 15 _ tboudreau 2013-11-08 04:45:57 UTC
It's particularly fun if you are on an airplane with no internet connection, and maven helpfully deletes your local copy of a snapshot dependency before it discovers it can't download a new one :-(

What about an invisible-when-disabled menu item, on the Build menu, which is disabled (and so disappears) if the current selection is not part of a Maven project?
Comment 16 Martin Balin 2016-07-07 08:37:56 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 17 markiewb 2016-07-10 19:29:37 UTC
Still valid in 8.2 dev 
Product Version: NetBeans IDE Dev (Build 201607100002)