-
Notifications
You must be signed in to change notification settings - Fork 564
[Xamarin.Android.Build.Tasks] Add support for @(AndroidMavenLibrary). #8420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
29e4d05
[Xamarin.Android.Build.Tasks] Add support for @(AndroidMavenLibrary).
jpobst 0da40eb
Apply suggestions from code review
jpobst 167575d
Use CancellationToken where available.
jpobst 62d33b9
Add tests.
jpobst 8a228ad
Localization, third party notices
jpobst 1cb9743
Add docs.
jpobst 7a8c6f8
Update MavenNet.
jpobst 37f7159
Appease PoliCheck.
jpobst c71b234
Small review changes.
jpobst 4b5d5df
Update Xamarin.Android.Bindings.Maven.targets
jonpryor 183f67b
Review feedback.
jpobst 2a0245b
Fix MSBuild error
jpobst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # AndroidMavenLibrary | ||
|
|
||
| Note: This feature is only available in .NET 9+. | ||
|
|
||
| ## Description | ||
|
|
||
| `<AndroidMavenLibrary>` allows a Maven artifact to be specified which will automatically be downloaded and added to a .NET Android binding project. This can be useful to simplify maintenance of .NET Android bindings for artifacts hosted in Maven. | ||
|
|
||
| ## Specification | ||
|
|
||
| A basic use of `<AndroidMavenLibrary>` looks like: | ||
|
|
||
| ```xml | ||
| <!-- Include format is {GroupId}:{ArtifactId} --> | ||
| <ItemGroup> | ||
| <AndroidMavenLibrary Include="com.squareup.okhttp3:okhttp" Version="4.9.3" /> | ||
| </ItemGroup> | ||
| ``` | ||
|
|
||
| This will do two things at build time: | ||
| - Download the Java [artifact](https://central.sonatype.com/artifact/com.squareup.okhttp3/okhttp/4.9.3) with group id `com.squareup.okhttp3`, artifact id `okhttp`, and version `4.9.3` from [Maven Central](https://central.sonatype.com/) to a local cache (if not already cached). | ||
| - Add the cached package to the .NET Android bindings build as an [`<AndroidLibrary>`](https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/building-apps/build-items.md#androidlibrary). | ||
|
|
||
| Note that only the requested Java artifact is added to the .NET Android bindings build. Any artifact dependencies are not added. If the requested artifact has dependencies, they must be fulfilled individually. | ||
|
|
||
| ### Options | ||
|
|
||
| `<AndroidMavenLibrary>` defaults to using Maven Central, however it should support any Maven repository that does not require authentication. This can be controlled with the `Repository` attribute. | ||
|
|
||
| Supported values are `Central` (default), `Google`, or a URL to another Maven repository. | ||
|
|
||
| ```xml | ||
| <ItemGroup> | ||
| <AndroidMavenLibrary | ||
| Include="androidx.core:core" | ||
| Version="1.9.0" | ||
| Repository="Google" /> | ||
| </ItemGroup> | ||
| ``` | ||
|
|
||
| ```xml | ||
| <ItemGroup> | ||
| <AndroidMavenLibrary | ||
| Include="com.github.chrisbanes:PhotoView" | ||
| Version="2.3.0" | ||
| Repository="https://repository.mulesoft.org/nexus/content/repositories/public" /> | ||
| </ItemGroup> | ||
| ``` | ||
|
|
||
| Additionally, any attributes applied to the `<AndroidMavenLibrary>` element will be copied to the `<AndroidLibrary>` it creates internally. Thus, [attributes](https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md#msbuild-item-groups) like `Bind` and `Pack` can be used to control the binding process. (Both default to `true`.) | ||
|
|
||
| ```xml | ||
| <ItemGroup> | ||
| <AndroidMavenLibrary | ||
| Include="androidx.core:core" | ||
| Version="1.9.0" | ||
| Repository="Google" | ||
| Bind="false" | ||
| Pack="false" /> | ||
| </ItemGroup> | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
build-tools/xaprepare/xaprepare/ThirdPartyNotices/MavenNet.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
|
|
||
| namespace Xamarin.Android.Prepare | ||
| { | ||
| [TPN] | ||
| class MavenNet_TPN : ThirdPartyNotice | ||
| { | ||
| static readonly Uri url = new Uri ("https://github.com/Redth/MavenNet/"); | ||
|
|
||
| public override string LicenseFile => string.Empty; | ||
| public override string Name => "Redth/MavenNet"; | ||
| public override Uri SourceUrl => url; | ||
| public override string LicenseText => @" | ||
| MIT License | ||
|
|
||
| Copyright (c) 2017 Jonathan Dick | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the ""Software""), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE."; | ||
|
|
||
| public override bool Include (bool includeExternalDeps, bool includeBuildDeps) => includeExternalDeps; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...amarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Maven.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <!-- | ||
| *********************************************************************************************** | ||
| Xamarin.Android.Bindings.Maven.targets | ||
|
|
||
| This file contains MSBuild targets used to enable @(AndroidMavenLibrary) support. | ||
|
|
||
| *********************************************************************************************** | ||
| --> | ||
|
|
||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <UsingTask TaskName="Xamarin.Android.Tasks.MavenDownload" AssemblyFile="Xamarin.Android.Build.Tasks.dll" /> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- Maven cache directory location --> | ||
| <MavenCacheDirectory Condition="$([MSBuild]::IsOSPlatform('Windows')) and '$(MavenCacheDirectory)'==''">$(LocalAppData)\dotnet-android\MavenCacheDirectory\</MavenCacheDirectory> | ||
| <MavenCacheDirectory Condition="$([MSBuild]::IsOSPlatform('OSX')) and '$(MavenCacheDirectory)'==''">$(HOME)/Library/Caches/dotnet-android/MavenCacheDirectory/</MavenCacheDirectory> | ||
| <MavenCacheDirectory Condition="'$(MavenCacheDirectory)'==''">$(HOME)/.cache/dotnet-android/MavenCacheDirectory/</MavenCacheDirectory> | ||
| <MavenCacheDirectory>$([MSBuild]::EnsureTrailingSlash('$(MavenCacheDirectory)'))</MavenCacheDirectory> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="MavenRestore" | ||
| Condition=" '@(AndroidMavenLibrary->Count())' != '0' " | ||
| BeforeTargets="_CategorizeAndroidLibraries" | ||
| DependsOnTargets="ResolvePackageAssets"> | ||
|
|
||
| <!-- Download artifacts and POMs from Maven to a local cache. --> | ||
| <MavenDownload MavenCacheDirectory="$(MavenCacheDirectory)" AndroidMavenLibraries="@(AndroidMavenLibrary)"> | ||
| <Output TaskParameter="ResolvedAndroidMavenLibraries" ItemName="_ResolvedAndroidMavenLibraries" /> | ||
| </MavenDownload> | ||
|
|
||
| <!-- Add @(AndroidMavenLibrary)'s to @(AndroidLibrary)'s. --> | ||
| <ItemGroup> | ||
| <AndroidLibrary Include="@(_ResolvedAndroidMavenLibraries)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Target> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 59 additions & 1 deletion
60
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we show an example of how you'd copy paste from here:
https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/4.9.3
And then turn it into our XML/MSBuild version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mvnrepository is agregate repo and most packages point to MavenCentral repo.
Pobst used proper maven name for
artifactIdwhich isgroupId:artifactIdhttps://maven.apache.org/guides/introduction/introduction-to-the-pom.html#minimal-pom
It would be nice to have FQ Maven Id with version too:
groupId:artifactId:versionthen MsBuildVersionattribute is not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale for a separate
Versionattribute is to mirror<PackageReference>and to allow MSBuild central versioning strategies to work, like:or
I suppose we could allow either format, but let's start with this one and see if there is any demand for alternative formats.